How to run a script directly when double clicked? [duplicate]

To execute a script, I have to:

  1. Write the script
  2. Make it executable
  3. Double click it, which shows this window:

    enter image description here

  4. Click the "Run" button.


How can I execute the script directly, without showing the dialog?


GUI

Depending on which Ubuntu version you have,

  • Before 13.04

    In Nautilus, go to this menu:

    Edit → Preferences

  • 13.04 and later

    In Nautilus, go to this menu:

    Files → Preferences

Then,

in the 'Behaviour' tab, enable "Run executable text files with they are opened"

enter image description here


Command line

If you prefer a command:

dconf write /org/gnome/nautilus/preferences/executable-text-activation "'launch'"

Note: Both GUI and command line methods work only for Nautilus (the default graphical file manager in Ubuntu)