Start desktop launcher from command line on Mint

6,537

Solution 1

You can use a tool like xdg-open (Broken currently), kde-open, gnome-open, gtk-launch or the equivalent for your desktop-environment. (xdg-open seems to be supposed to be the universal one...)

(It seems like just about everything other than gtk-launch (more similar tools might exist for other toolkits) suffers from the same bug as xdg-open - it opens the .desktop file in an editor instead of running it)

Packages: (Exact name will differ betweem distros) (this is based on CentOS 7)

  • gtk3 for gtk-launch
  • xdg-utils for xdg-open
  • kde-runtime for kde-open
  • libgnome for gnome-open

Solution 2

If you really want this, I suggest you write a little function that extracts the executable name from the .desktop file and runs it. Add these lines to your shell's initialization file (e.g. ~/.bashrc):

runDesktop () {
  eval "$(awk -F= '$1=="Exec"{$1=""; print}' "$1")"
}

Then, you can run your .desktop file with runDesktop ~/Desktop/slack.desktop. Of course, the usual caveats concerning eval apply.

You could try making it a bit more complicated sophisticated:

runDesktop () {
  comm=( $(awk -F= '$1=="Exec"{$1=""; print}' "$1") )
  "${comm[0]}" "${comm[@]:1}" &
  disown
}

Solution 3

The dex application is probably the simplest way to do this.

sudo apt install dex and then dex ~/Desktop/some-application.desktop or since many/most system applications are in /usr you could use dex /usr/share/applications/some-application.desktop.

Share:
6,537

Related videos on Youtube

Vadim Zverev
Author by

Vadim Zverev

Updated on September 18, 2022

Comments

  • Vadim Zverev
    Vadim Zverev over 1 year

    Can I start a desktop launcher from command line? E.g. I have a desktop launcher for slack in my ~/Desktop directory:

    vadim@my-pc ~/Desktop $ cat slack.desktop 
    [Desktop Entry]
    Name=Slack
    Comment=Slack Desktop
    GenericName=Slack Client for Linux
    Exec=/usr/bin/slack --proxy-server="10.1.50.8:8080"
    Icon=/usr/share/pixmaps/slack.png
    Type=Application
    StartupNotify=true
    Categories=GNOME;GTK;Network;InstantMessaging;
    MimeType=x-scheme-handler/slack;
    Name[en_US]=slack
    

    In the Exec parameter I can specify various options to start application with, for instance proxy server. I find it convenient to specify proxy exactly in the parameters of desktop launcher.

    Now I'd like to be able to start slack from command line using all start options from the desktop launcher. I know I can create a shell script file and specify in it all start options I want and run this file both from desktop launcher and from command line, but is there a way to just run slack.desktop file from command line?

    • terdon
      terdon almost 6 years
      I don't understand. It is much simpler, faster and easier to use a script, a function, or an alias for this. Why would you want to go to the trouble of using a desktop file?
    • Vadim Zverev
      Vadim Zverev almost 6 years
      @terdon I find it convenient to change proxy and other settings through gui window by right-clicking on launcher icon on my desktop. I mostly start slack by clicking desktop launcher, but also want to be able to start it from command line in some cases.
    • Gert van den Berg
      Gert van den Berg almost 6 years
    • Vadim Zverev
      Vadim Zverev almost 6 years
      @GertvandenBerg Hm, it seems to be exactly my question. I tried gtk-launch slack.desktop from one of the answers and it works! I guess my question should be marked as duplicated.
    • Gert van den Berg
      Gert van den Berg almost 6 years
      It was on a different site (And Mint questions would be off-topic on AskUbuntu), so I'm not sure if it counts as a duplicate...
    • terdon
      terdon almost 6 years
      @VadimZverev if gtk-launch worked for you, you might want to accept Gert's answer instead of mine, since that one mentions it.
  • Vadim Zverev
    Vadim Zverev almost 6 years
    It works, thanks. But when I close a terminal slack is being killed. I tried to unbind slack from terminal by changing a command to nohup "${comm[0]}" "${comm[@]:1}" & and I see that now slack starts kind of asynchronously, but still slack is being killed after closing a terminal.
  • terdon
    terdon almost 6 years
    Both xdg-open and gnome-open open the desktop file for editing instead of executing. Presumably because of the bug you linked to. Shame, this would indeed have been a better way.
  • terdon
    terdon almost 6 years
    @VadimZverev use disown. See updated answer.
  • Vadim Zverev
    Vadim Zverev almost 6 years
    Yes, disown did the trick.
  • terdon
    terdon almost 6 years
    That gives me gtk-launch: no such application /home/terdon/Desktop/foo.desktop (and yes, foo.desktop exists and can be launched by double clicking). I'm using Arch and Cinnamon. Have you managed to get any of these to work on your system?
  • Gert van den Berg
    Gert van den Berg almost 6 years
    @terdon I'm currently a bit far from an up to date *nix system using a GUI. gtk-launch was added based on the OP's comment that it worked for him. gtk-launch seems to be provided in the gtk3 package
  • terdon
    terdon almost 6 years
    Ah, nice, +1 then. I have gtk-launch, it just doesn't like .desktop files on my system for some reason.