Opening new Terminal.app window/tab with a certain profile from command-line or AppleScript? When I login to my Mac, I want to automatically open a new Terminal.app window with a certain profile, say Monitor, that has a startup command and several appearance settings.  I thought it would be very easy to do this from AppleScript or command-line (via osascript), so I can add a script to my login items, but it turns out this is not so trivial after several tries.

My current best way is the following AppleScript:

tell application "Terminal"
    set origSettings to default settings
    set default settings to settings set "Monitor"
    activate
    tell application "System Events" to keystroke "n" using command down
    set default settings to origSettings
end tell


However, I want to know if there's a simpler way to do this without relying on UI scripting (with System Events) or messing around with my Terminal's default settings.

applescript (osascript) for changing Terminal.app profile seemed promising, but it's for when there's already a Terminal window open.  I have no idea how to create a new Terminal tab or window with its current settings specified.  The do script command, which does create a new window, unfortunately ignores the startup command set in the profile, making me fall back to UI scripting.

I also found this script: http://blog.azizlight.me/having-fun-with-applescript-and-terminal-app/ which again relies on UI scripting.  Because some of my machines use non-English locale, I prefer sticking to keystrokes rather than menu labels.
Can you just run the startup command with do script?

tell application "Terminal"
    do script "emacs"
    set current settings of selected tab of window 1 to settings set "Grass"
end tell


If someone else doesn't need to run any startup command, you can use do script "" to open a new window:

tell application "Terminal"
    do script ""
    set current settings of selected tab of window 1 to settings set "Grass"
end tell


Or you could also use do script "" when changing default settings:

tell application "Terminal"
    set old to default settings
    set default settings to settings set "Grass"
    do script ""
    set default settings to old
    activate
end tell