Home Download Buy Blog Forum Support

Linux .desktop file

Linux .desktop file

Postby jalaziz on Sat Feb 19, 2011 9:24 am

Hey Everyone,

I've create a basic sublime.desktop file for Linux. This will both automatically show Sublime in Gnome's menus and allow you to set Sublime as the default editor for your files. If you're using Ubuntu, this file should be placed in the /usr/share/applications directory.

You will have to edit the file to point to the location of the icon you wish to use. I simply used the logo from this post: http://www.sublimetext.com/forum/viewtopic.php?f=2&t=1558&p=7373#p7373

Hope this helps someone.
Attachments
sublime.desktop.zip
(330 Bytes) Downloaded 736 times
jalaziz
 
Posts: 3
Joined: Sat Feb 19, 2011 9:14 am

Re: Linux .desktop file

Postby senshikaze on Mon Feb 28, 2011 1:51 pm

If you prefer not to have to mess with root, you can put it in ~/.local/share/applications/ as well. This will make it only show up for your account though. I personally put all my non-deb packaged programs into ~/.bin so I don't have to muddle with the system. Hopefully by release they will have a .deb and a .rpm.
senshikaze
 
Posts: 3
Joined: Mon Feb 28, 2011 1:48 pm

Re: Linux .desktop file

Postby knitatoms on Wed Mar 02, 2011 1:04 pm

I'm trying this under XFCE (Crunchbang linux / Debian squeeze) and I get the menu fine.

However when Sublime opens up after click on a file from the file manager the contents of the file are not displayed. If I drag and drop files into Sublime they open fine. I'm using the latest Alpha of Sublime 2. Anyone else have this problem?

Here's my sublime.desktop file:
Code: Select all
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Sublime Text
GenericName=Text Editor
Comment=Edit source code
Exec="/home/tom/bin/Sublime Text 2/sublime_text" %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=/home/tom/images/sublime.png
Categories=TextEditor;Development;Utility;
knitatoms
 
Posts: 22
Joined: Sat Feb 06, 2010 9:01 am

Re: Linux .desktop file

Postby senshikaze on Wed Mar 02, 2011 8:11 pm

remove the %U in the exec line. It just opened a blank file called %U for me. Using LinuxMint 10 and GNOME.
senshikaze
 
Posts: 3
Joined: Mon Feb 28, 2011 1:48 pm

Re: Linux .desktop file

Postby knitatoms on Thu Mar 03, 2011 5:10 pm

Thanks for the reply but it doesn't make any difference for me. This could just be me not understanding XFCE but based on the other .desktop files it should work.

When I click a file that has been set to open with Sublime I get a new instance of Sublime every time and also the contents of the window is blank. This happen whether I have %U or not. See attached screenshot:
Attachments
screenshot.png
screenshot.png (58.35 KiB) Viewed 6226 times
knitatoms
 
Posts: 22
Joined: Sat Feb 06, 2010 9:01 am

Re: Linux .desktop file

Postby jalaziz on Fri Mar 04, 2011 9:06 am

senshikaze wrote:If you prefer not to have to mess with root, you can put it in ~/.local/share/applications/ as well. This will make it only show up for your account though. I personally put all my non-deb packaged programs into ~/.bin so I don't have to muddle with the system. Hopefully by release they will have a .deb and a .rpm.


I agree, ~/.local/share/applications/ is actually a better place to put the desktop file. That being said, I prefer to put locally installed programs in ~/opt and then link the binaries in ~/bin (the local bin folder should automatically added to your path, at least that's what happens on all my Ubuntu machines).

Also, I am willing to create a deb and setup a ppa for Ubuntu if jps gives me the ok.
jalaziz
 
Posts: 3
Joined: Sat Feb 19, 2011 9:14 am

Re: Linux .desktop file

Postby jalaziz on Fri Mar 04, 2011 9:14 am

knitatoms wrote:Thanks for the reply but it doesn't make any difference for me. This could just be me not understanding XFCE but based on the other .desktop files it should work.

When I click a file that has been set to open with Sublime I get a new instance of Sublime every time and also the contents of the window is blank. This happen whether I have %U or not. See attached screenshot:


http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html defines the specs for the .desktop file. The spec is meant to be implementation agnostic, and %U is defined as "A list of URLs. Each URL is passed as a separate argument to the executable program. Local files may either be passed as file: URLs or as file path." I'm not entirely sure why it doesn't work for you, but try opening any .desktop file for a program that does work (found in /usr/share/applications) in a text editor. That should give you an idea of what does work on your system.
jalaziz
 
Posts: 3
Joined: Sat Feb 19, 2011 9:14 am

Re: Linux .desktop file

Postby jps on Fri Mar 04, 2011 9:55 am

Try using %F rather than %U: Sublime Text 2 expects a list of file names as arguments, rather than URLs.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: Linux .desktop file

Postby knitatoms on Fri Mar 04, 2011 10:51 am

jps wrote:Try using %F rather than %U: Sublime Text 2 expects a list of file names as arguments, rather than URLs.


Thanks - that helps - I now get the content of the file. But I still get a new instance of Sublime for each file opened. The docs suggest %F (capital F) should prevent that.

Gedit works fine and new files open in a new tab. My gedit .desktop file has the same settings as the Sublime .desktop file.

Maybe a Sublime issue or does it work OK for other people?
knitatoms
 
Posts: 22
Joined: Sat Feb 06, 2010 9:01 am

Re: Linux .desktop file

Postby jps on Fri Mar 04, 2011 11:33 am

Sublime Text 2 requires a very recent version of GIO (part of gnome) for single instance support. If you run it from a terminal, it'll print a message to stderr if single instance support is disabled.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Majestic-12 [Bot] and 24 guests