user2454182
user2454182

Reputation:

Shortcut to running Mac Terminal commands

Ok... I've been searching for an answer to this for a while and can't seem to find any good examples, so I thought I'd break down and ask.

How can I create a shell file (.command) in OSX that I can just double-click on which:

My goal is to setup various environments using individual .command files, which will each set variables and run certain command line tools, and then remain open to manually run other commands. I currently have one like this:

#!/bin/sh

export MY_VAR_A="blah A"
export MY_VAR_B="blah B"

cd /Users/

... and this doesn't work. It just opens a Terminal window with this output:

Last login: Sat Aug 17 12:52:15 on ttys000
unknown60c5470527e4:~ me$ /Users/me/Documents/test.command ; exit;
logout

[Process completed]

Is there a better (or just different) way of accomplishing what I want? Or do I just need to adjust something simple in my current .command file?

Upvotes: 3

Views: 9144

Answers (1)

Parag Bafna
Parag Bafna

Reputation: 22930

Use applescript

tell application "Terminal" to activate
tell application "Terminal"
    do script ("ls -l") in window 1
    do script ("cd /Users/test/Music/iTunes/") in window 1
    do script ("ls -l") in window 1
end tell

Save apple script as application bundle.

Upvotes: 3

Related Questions