How do I set up a shell script to execute from the Mac OSX dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set som
On OSX Mavericks:
Make your shell script executable:
chmod +x your-shell-script.sh
Rename your script to have a .app
suffix:
mv your-shell-script.sh your-shell-script.app
Rename your script back to a .sh
suffix:
mv your-shell-script.app your-shell-script.sh
Now when you click on the script in the dock, A terminal window will pop up and execute your script.
Bonus: To get the terminal to close when your script has completed, add exit 0
to the end and change the terminal settings to "close the shell if exited cleanly" like it says to do in this SO answer.
As joe mentioned, creating the shell script and then creating an applescript script to call the shell script, will accomplish this, and is quite handy.
Create your shell script in your favorite text editor, for example:
mono "/Volumes/Media/~Users/me/Software/keepass/keepass.exe"
(this runs the w32 executable, using the mono framework)
Save shell script, for my example "StartKeepass.sh"
Open AppleScript Editor, and call the shell script
do shell script "sh /Volumes/Media/~Users/me/Software/StartKeepass.sh" user name "<enter username here>" password "<Enter password here>" with administrator privileges
do shell script
- applescript command to call external shell commands"sh ...."
- this is your shell script (full path) created in step one (you can also run direct commands, I could omit the shell script and just run my mono command here)user name
- declares to applescript you want to run the command as a specific user"<enter username here>
- replace with your username (keeping quotes) ex "josh"password
- declares to applescript your password"<enter password here>"
- replace with your password (keeping quotes) ex "mypass"with administrative privileges
- declares you want to run as an adminsave your applescript as filename.scpt, in my case RunKeepass.scpt
save as... your applescript and change the file format to application, resulting in RunKeepass.app in my case
Copy your app file to your apps folder
I think this thread may be helpful: http://forums.macosxhints.com/archive/index.php/t-70973.html
To paraphrase, you can rename it with the .command extension or create an AppleScript to run the shell.