How to escape spaces in .desktop files Exec line

Solution 1:

Precede each space by a backslash:

[Desktop Entry]
Name=Sublime Text 2
GenericName=Sublime Text 2
Comment=Edit text files
Exec=/home/user/opt/sublime/Sublime\ Text\ 2/sublime_text %U

Solution 2:

According to the desktop entry specification ASCII space may be represented by the \s escape sequence (for string and localestring values).

Solution 3:

I was having exactly the same problem! After trying various escaping/quoting patterns, I decided the simplest solution was to have a symbolic link to sublime_text on my $PATH (or you could use a command-line alias).

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[C]=/usr/share/Sublime Text 2/Icon/256x256/sublime_text.png
Name[C]=Sublime Text 2
Exec=Sublime-Text-2 %U
Comment[C]=Text Editor
Name=Sublime Text 2
Comment=Text Editor
Icon=/usr/share/Sublime Text 2/Icon/256x256/sublime_text.png
X-Desktop-File-Install-Version=0.21