9

Is it possible to get an executable to execute by default?

What I mean is this. I have an .sh file, which if I click on twice, it will show me this:

enter image description here

If I then click Execute, it does the right thing. Is it possible to get it to Execute without being shown the Execute File dialog box? So simply by double clicking the .sh file, it should do its thing without showing me the Execute File dialog box.

I am using Lubuntu/PCManFM if that info is needed.

Mat
  • 51,578
  • 10
  • 158
  • 140
oshirowanen
  • 2,571
  • 15
  • 46
  • 66
  • You can use `xdg-mime query filetype shell_script.sh` to find the mime type of the script. Afterwards, use `xdg-mime query default mime_type` to see the current default application associated with the mime type, which is called upon `xdg-open` invocation. Then you can use `xdg-mime default default_application.desktop mime_type` to set the default application to be used. Find details [in this answer](https://unix.stackexchange.com/a/643473/318461)! – Cadoiz Oct 20 '21 at 14:31

2 Answers2

4

You have to create a "Desktop Entry" like this (not tested):

#!/usr/bin/env xdg-open
[Desktop Entry]
Encoding=UTF-8
Type=Application
X-Created-By= name
Icon= icon
Exec="path_of_file" %u
Name=name of program
Cadoiz
  • 268
  • 1
  • 11
Pol Hallen
  • 2,067
  • 7
  • 23
  • 31
  • I created a [script to automatically generate these `.desktop`-files](https://unix.stackexchange.com/a/674052/318461), which can be considered. The `%u` means "pass all parameters to the script", [right?](https://unix.stackexchange.com/questions/189777/how-to-launch-shell-script-with-double-click-in-centos-7/189779#comment1272132_189779) Is the `Encoding` important? You could also add `Terminal=false` if needed. – Cadoiz Oct 20 '21 at 16:02
2

When double-clicking an icon on the desktop, to avoid presenting the "Execute File" dialog, do the following:

  • Open File Manager
  • Select Edit → Preferences → General
  • Tick the option "Don't ask options on launch executable file"
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164