5
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Link
Name=ShareFolder
Icon=/usr/share/icons/DPL/NetworkShare.png
Name[en_US]=ShareFolder
URL=smb://servername/sharefolder

This is my .desktop file which has a URL. How do I execute this desktop shortcut in the terminal? If i double click it works perfectly, but I need to execute this in terminal.

I tried Running a .desktop file in the terminal. That didn't work for me either but it does if its an "application" shortcut. I'm trying here to execute "link" .desktop file, where you define in the type section (Type=Link) and (URL=smb://servername/sharefolder)

Pubudug
  • 51
  • 1
  • 4

2 Answers2

3

Use

xdg-open path/to/file.desktop

The first line in the file is the application that runs that file.

If this does not work, try this (adopted from Running a .desktop file in the terminal):

xdg-open `grep '^URL' path/to/file.desktop | tail -1 | sed 's/^URL=//' | sed 's/%.//'` &
Danatela
  • 13,384
2

Sorry for reviving, but the other answer seems incorrect since it simply opens the .desktop file in a text editor. If you want to "execute" the desktop variable, i.e. simulate double-clicking it from a desktop environment, use the appropriate launcher for your desktop environment.

On Cinnamon, Gnome, Gnome Flashback, and MATE, you want gio launch path/to/file.desktop.

The wiki page below should help you find the appropriate launcher for your DE if you're not using Cinnamon/Gnome/Gnome Flashback/MATE.

Reference: https://wiki.archlinux.org/title/Desktop_entries