I figured out the basics but not details of generating a .desktop
-file.
More Specification can be found here.
The mandatory (bare minimum) lines seem to be these:
#!/usr/bin/env xdg-open
[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec="path_of_file" %u
Terminal=false
The %u is (only) needed if you want to pass parameters to the script. There are also other possible entries such as Name
, Comment
, Icon
or X-Created-By
:
Name=My script
Comment=Test hello world script
Icon=/home/user/youricon.png
X-Created-By= your name
In order to improve the ease of creating these, I provide this script:
#!/bin/bash
echo "#!/usr/bin/env xdg-open
[Desktop Entry]
Encoding=UTF-8
Exec=\"$1\"
Terminal=false
Type=Application
$3" > "$2"
You can use this script like this: $ make_script_click_runnable.sh "path_of_file" "YourClickRunnableFile.desktop"
. (Depending on your link and file name, this usually also works without the quotes ".)
If you want to include the optional parameters, this could be a call you use: $ make_script_click_runnable.sh "path_of_file" "YourClickRunnableFile.desktop" $"Name=My script\nComment=Test hello world script\nIcon=/home/user/youricon.png\nX-Created-By= your name"
. Using the $3
-parameter (see above), the optional ones are appended, but don't forget the $
before $Name=My Script\n...
- I didn't find a more elegant way yet to resolve the \n
s.
You can also use basically the same script to create "hyperlinks" to URLs, as http, only the Type
has to be changed and URL
is used instead of Exec
:
Type=Link
URL=http://example.com/your/link
Icon=text-html
Notice the standard-icon text-html
. For more details on that, please consider this answer on the respective question.