2

/usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new is the linux command for creating Desktop shortcuts.

So naturally the first shortcut I need is a short cut to the command:

/usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new

When I create the shortcut it will not execute. I am using 18.04 and the text of the shortcut created is below. I have also created it with Terminal attribute set to true but that also sits there and does nothing. I have also tried placing the command inside a bash shell script and making sure everything is executable. Nothing works.

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=gnome-panel-launcher
Name[en_US]=CreateLauncher
Exec=/usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new
Name=CreateLauncher
Icon=gnome-panel-launcher
PRATAP
  • 22,460
blogman
  • 83
  • 2
  • 8
  • What's the full output of the gnome-desktop-item-edit command you're trying to run, when you run it in a terminal? Does it wait for input, or finish immediately? – Xen2050 Jan 25 '19 at 14:42
  • It throws up a little dialog box that asks for the shortcut deatails. – blogman Jan 25 '19 at 14:45
  • I have done this before in past ubuntu versions from a few years ago. I am an Ubuntu prodigal son. Creating a shortcut to the shortcut command is one of my first acts of business when I create an Ubuntu instance... – blogman Jan 25 '19 at 14:49
  • Hmm, seems like it should run then. Maybe the gnome-desktop-item-edit doesn't like to run non-interactively. Could verify the first shortcut is even working, change the Exec line to something noticeable, like play a sound or zenity --warning --text="Test desktop" – Xen2050 Jan 25 '19 at 14:57

2 Answers2

1

It seems the error lies in Exec value. Desktop entries need absolute paths. So, replace ~/Desktop/ with /home/username/Desktop/ such that value of Exec in desktop entry looks like:

Exec=/usr/bin/gnome-desktop-item-edit /home/username/Desktop/ --create-new

Explanation:

From Desktop Entry Specification -

The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment. The name or path of the executable program may not contain the equal sign ("="). Arguments are separated by a space.

Kulfy
  • 17,696
  • 1
    @blogman This isn't a bug but it is doing what it is intended to do. I've updated my answer to include explanation. – Kulfy Jan 25 '19 at 20:03
  • The original command line "/usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new" that uses the absolute path to the desktop folder has been documented for a long time and I am pretty sure that I was able to use it as is in a shortcut in past Ubuntu versions. So I was mistaken to say the bug is in the gnome-desktop-item-edit command. Rather the bug would be in the operating system's failure to expand the absolute path prior to executing the command. – blogman Jan 26 '19 at 12:59
  • As an example execute the command zenity --warning --text=$HOME from the command line and then from a shortcut either with Terminal set to True or False. In the latter case the dialog box displays "$HOME" rather than the value of the $HOME environment variable. Shouldn't their be some expectation of the short cut exec functionality being able to pick up the environment when parsing command lines? It is capable of finding the command itself in the path because the full path to the command being executed needn't be provided. – blogman Jan 26 '19 at 13:40
  • Here is another example but it only runs sometimes:

    #!/usr/bin/env xdg-open

    [Desktop Entry] Version=1.0 Type=Application Terminal=true Icon[en_US]=gnome-panel-launcher Name[en_US]=Testecho Exec=echo $HOME Name=Testecho Icon=gnome-panel-launcher

    – blogman Jan 26 '19 at 13:53
  • The absolute paths work within a shell script – blogman Jan 26 '19 at 14:33
  • @blogman There is a difference in shell script and Desktop Entry. As I said earlier this isn't a bug but it is supposed to be like this. If you remember that Ubuntu version where $HOME or tilde(~), let me know that. I'll try to test on that also. According to Jacob's answer: In a .desktop file, you need to use absolute and full paths. Therefore ~ is not expanded. If you have any further doubts you can always ask a new question. May be someone could post a well explanatory answer there. Thanks :) – Kulfy Jan 26 '19 at 18:42
  • I am not confusing shell scripts and desktop entries. My point is that a desktop entry that executes a shell script will work when the absolute paths are referenced in the shell script and not referenced directly in execute attribute of the desktop entry. It works that it is what I am using after implementing PRATAP's solution. See above. It works – blogman Jan 26 '19 at 19:03
  • @blogman I see in PRATAP's answer, desktop entry was just used to call the script and there too full path of script was used in Exec's value. Desktop entry just called the script and everything else was handled by script. Scripts seem to expand ~ as home. So, all work is done by script, desktop entry created just another way to launch the script. – Kulfy Jan 26 '19 at 20:17
0

I could do this with the below way..

  1. create a script named cl.sh on Desktop to run the command /usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new with below content.

    Content of the script

    #!/bin/bash
    
    /usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new
    
  2. cd ~/Desktop

  3. Make the script executable with chmod a+x cl.sh
  4. Open the "Create Launcher" with ./cl.sh
    A dialog "Create Launcher" will pop up.
  5. Give the command as /home/user/Desktop/cl.sh Replace user with your username
  6. Click the Icon on Desktop and click trust and launch.

enter image description here

PRATAP
  • 22,460
  • Thanks - that's exactly what I am trying to do. When I put the /usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new in a shell script like you did the resulting shortcut raises a launch error. If I put the /usr/bin/gnome-desktop-item-edit ~/Desktop/ --create-new command directly in the shortcut it doesn't do anything. – blogman Jan 25 '19 at 17:53
  • the shell script runs fine from the command line. Also the other test that you suggested worked: – blogman Jan 25 '19 at 17:57
  • #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Terminal=false Icon[en_US]=gnome-panel-launcher Name[en_US]=Test Exec=zenity --warning --text="Test desktop" Name=Test Icon=gnome-panel-launcher – blogman Jan 25 '19 at 17:57
  • I am using ubuntu 18.04 – blogman Jan 25 '19 at 18:03
  • Just curious, what ubuntu version did you do this in? In 18.04 it only worked with the full path to desktop folder - /home/{whatever}/Desktop. – blogman Jan 26 '19 at 14:08
  • i did it on 18.04 and 18.10 both.. – PRATAP Jan 26 '19 at 14:09
  • 1
    I just tried it your way and it worked this time. I guess the deal is that if the commands are executed within the context of the environment of a shell script the absolute paths are resolved. The Exec functionality, by itself, has no context... – blogman Jan 26 '19 at 14:21