Macos – Run a shell script on OS X without having a terminal window appear

keyboard shortcutsmacosshell-scriptterminal

I'm trying to set up a few keyboard shortcuts that open specific iTerm sessions, which I was able to do with BetterTouchTool and a bit of AppleScript magic. The problem is that OS X insists to open a Terminal window for any shell script you execute through the GUI (i.e. from Finder, or as a keyboard shortcut from BetterTouchTool). The terminal window doesn't appear if I run the script directly from another terminal.

A workaround I found was to wrap the script in an .app directory, which solves the problem of the superfluous terminal window, but has some other issues (for example OS X seems to treat each resulting iTerm window as a separate app, cluttering my dock). (EDIT: this behaviour was actually caused by a bug in my script, see below)

I also tried assigning the Terminal app to another virtual desktop in the Spaces settings in an attempt to move it out of sight, but then it will just first switch to that desktop before running the script.

Is there a way to disable this behaviour completely? I already found the setting in the Terminal preferences to close the window after the script has finished, but it's still annoying to have the Terminal window pop up for a second.

Best Answer

Open Automator, choose Application, add a Run Shell Script action and put in your Shell command between quotes (if you have a file, you can just drag and drop it).

Other than playing it, now you can save it (as an app anywhere) and even set the icon.