MacOS – Execute command on launch of custom Terminal Window in OSX10.5+

macosplistterminal

I'm trying to find a way to automatically launch a command when Terminal is run, but:

  1. Have the Terminal window close after command has returned control to it / after (using &) after command has started launching.
  2. Not have the user change any settings themselves / not have the settings changed globally.

I have found (mainly from a relatively very comprehensive write-up on http://docstore.mik.ua/orelly/unix3/mac/ch01_03.htm) the ability to create a .terminal file and edit the contents (plist) to contain xml like the below.

    <key>ExecutionString</key>
    <string>ssh xyzzy.oreilly.com; exit</string>

However:

  1. Given the date of other postings (on google) showing this functionality
  2. The fact that the procedure which I eventually found to create custom Terminal windows, was subtly different from the instructions in the article above
  3. The fact that (at least with OSX10.5) they are now .term files (and complain that the file is not executable if changed to .terminal)

… am guessing that some version of OSX, post all the information I can find on this technique, changed this functionality. Is this correct in any version of OSX 10.5+?

Also, is there still a way to launch a command automatically in a custom terminal window (or similar, that isn't AppleScript / Automater / etc)?

Best Answer

ExecutionString was changed to CommandString Use it in the same way. When you do a Shell > Export Settings… it outputs a .terminal file. In my file it is located immediately after

<key>BackgroundSettingsForInactiveWindows</key>
<true/>
<key>CommandString</key>
<string>/blah/blah/blah/blah.sh run</string>

(MountainLion 10.8.5)

So then you would run the following command from terminal or a script…

open ~/Documents/blah.terminal