0

Hope, this belongs here and not e.g. on SU. I would like to make my life a bit easier and therefore want to be able to run a script.sh from file manager. This is possible in other distributions (or their software/presets), see here: PCManFM Feature
but I don't want to switch to another FM just for this. The file is executable as per chmod +x script.sh. I'm using openSUSE Leap version 15.1 with Plasma, Gnome or IceWM as a window-manager if this is important. The kernel is 4.12.14-lp151.28.91-default and I have Files (Gnome) 3.26.2, but I'm sure that this also applies to many other configurations. Dolphin would also be an option for File Management.

I also tried to configure a .desktop-file like suggested here, but didn't get it right.

1

1 Answer 1

0

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 \ns.


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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .