Run shell script by double clicking in non-login prompt in terminal
Question
This question is super similar to this, but I'm curious how to launch the shell script in a non-login shell prompt. I already have it set up to run with iterm2 when I double-click. I don't really care if it uses iterm2 or Terminal, I can easily switch that if needed. I really am just interested in getting it to run in a non-login prompt.
I have my script set to run by dash (!#/usr/bin/env dash
) but because it first starts up a zsh login prompt it sometimes prompts me things I don't want it to bother with (e.g., starting my ssh agent and asking if I want to update oh-my-zsh).
My guess (I might be wrong) is that if it started as a non-login prompt it wouldn't try to do these things. If it turns out that zsh non-login prompt still does this then I can probably set it up to run straight in dash in a similar way.
Solution
The Automator application can be used to create an application that will run a shell script. The steps are given below.
- Open the Automator application.
- Choose
New Document
. Highlight the icon labeled
Application
, then selectChoose
.Under
Library
, selectUtilities
, then dragRun Shell Script
to the window labeledDrag actions or files here to build your workflow.
Change
Pass input:
toas arguments
, as shown below.Replace the script with your own text. A simple example is given below.
From the menu bar, select
File->Save...
, as shown below. When done selectSave
.Quit the Automator application.
(Optional) Find the new application in the Finder. Right click on the new application and select
Get Info
. Drag and drop a new icon set (.icns
) file over the existing icon for the application, as shown below.The result is shown below.
Note: A
.icns
is not the same as a.jpg
or.png
file. You have to convert.jpg
or.png
to a.icns
file before being used as a icon.Test the new application. In this case, double clicking on the icon for the new application in the Finder produces the popup shown below.