Showing posts with label Desktop. Show all posts
Showing posts with label Desktop. Show all posts

Monday, January 25, 2010

Desktop file format

Confused about all the .desktop files in Gnome / KDE? There is an official spec at: www.freedesktop.org/wiki/Specifications/desktop-entry-spec.

Where are they?

All User files are in /usr/share/applications
Personal files are in $HOME/.local/share/applications

Gnome additions: / Autostart

 
X-GNOME-Autostart-enabled=true

should be set for files in $HOME/.config/autostart. This describes autostart applications. More info on autostart: KDE Bug #170817.

Find mime-type for a file

Here is how to determine the mime-type for a given file on the command line.

OS X

file --mime '''filename''

Linux

xdg-mime query filetype '''filename'''
gvfs-info -a standard::content-type '''filename''' | grep content | cut -d: -f4 | cut -d\  -f2-
gnomevfs-info '''filename''' | grep MIME | cut -d\: -f2- | cut -d\  -f2-
file --mime '''filename''' | cut -d\: -f2- | cut -d\  -f2

Everywhere

Update: We can modify the conditional alias to support mime types as well:

conditional_alias2 () {
  UNSET=false
  alias $1 > /dev/null 2>&1 || UNSET=true
  [ $UNSET = true ] && which $2 > /dev/null 2>&1 && alias $1=$3
}
mime_gvfs() {
  gvfs-info -a standard::content-type $1 | grep content | cut -d: -f4 | cut -d\  -f2-
}
mime_xdg() {
 xdg-mime query filetype $1
}
mime_gnomevfs() {
 gnomevfs-info file://$PWD/$1 | grep MIME | cut -d\: -f2- | cut -d\  -f2-
}
conditional_alias2 mime gvfs-info mime_gvfs
conditional_alias2 mime xdg-mime mime_xdg
conditional_alias2 mime gnomevfs-info mime_gnomevfs

Command Line Open in UNIX

On OS X I can just "open" any file. On Windows, I can use "start". And on Linux? On modern installations, the "xdg-open" command works just fine. Unfortunately - this is not always the case. And I don't want to remember different commands for different machines. So here is the ultimate open alias setting for bash, for all systems that I use (it can be easily extended for other environments).


 
conditional_alias() {
  UNSET=false
  alias $1 > /dev/null 2>&1 || UNSET=true
  [ x$UNSET = xtrue ] && which $2 > /dev/null 2>&1 && alias $1=$2
}
 
conditional_alias open gvfs-open
conditional_alias open xdg-open
conditional_alias open gnome-open
conditional_alias open exo-open
uname | grep MINGW > /dev/null 2>&1 && alias open=start