command line - Running a .desktop file in the terminal - Ask Ubuntu


from can gather, .desktop files shortcuts allow application's settings customized. instance, have lots of them in /usr/share/applications/ folder.

if open folder in nautilus, can run these applications double clicking associated file, e.g. double-clicking firefox.desktop runs firefox. however, can't find way same thing via terminal.

if gnome-open foo.desktop opens foo.desktop text file. if make executable , run in bash fails (which expected, it's not bash script).
edit: doing exec /fullpath/foo.desktop gives me permission denied message, if change ownership myself. if make executable , same command, terminal tab i'm using closes (i'm guessing crashes). finally, if sudo exec /fullpath/foo.desktop, error reporting sudo: exec: command not found.

that's question, how can run foo.desktop file terminal?

the command run contained inside desktop file, preceded exec= extract , run by:

`grep '^exec' filename.desktop | tail -1 | sed 's/^exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g'` & 

to break down

grep  '^exec' filename.desktop    - finds line starts exec | tail -1                         - use last line, in case there multiple | sed 's/^exec=//'                - removes exec start of line | sed 's/%.//'                    - removes arguments - %u, %f etc | sed 's/^"//g' | sed 's/" *$//g' - removes " around command (if present) `...`                             - means run result of command run here &                                 - @ end means run in background 

you put in file, ~/bin/deskopen contents

#!/bin/sh `grep '^exec' $1 | tail -1 | sed 's/^exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g'` & 

then make executable

chmod +x ~/bin/deskopen 

and do, eg

deskopen /usr/share/applications/ubuntu-about.desktop 

the arguments (%u, %f etc) detailed @ http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html#exec-variables - none of them relevant launching @ command line.


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User