How to launch .sh scripts from the finder in iTerm2 instead of Terminal

command linefinderiterm

I have set 'always open with' to : 'Iterm2', for .sh files in osX.
Although a double click on a shell script now opens a new Iterm window, the script does not actually run, I just the get the empty prompt.
There might be an applescript solution, but I would prefer a more direct way.

Best Answer

It works for me but only if the file is executable. For example this runs a.sh in a new window:

echo say a>a.sh;chmod +x a.sh;open a.sh -a iTerm

If you want it to work with non-executable files, set an application like this as the default application for .sh files: