Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to merge two osascript scripts, so that with one command I can open a new terminal tab and execute a script like echo hello into that new tab.

This one opens a new terminal tab.

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down'

This one opens a new window and runs echo hello

osascript -e 'tell app "Terminal" do script "echo hello" end tell'
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I don't know any better way to make a new tab, but you can run a command in the frontmost tab or window with do script "" in window 1.

tell application "Terminal"
    activate
    tell application "System Events" to keystroke "t" using command down
    repeat while contents of selected tab of window 1 starts with linefeed
        delay 0.01
    end repeat
    do script "echo a" in window 1
end tell
share|improve this answer
add comment

Try

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e 'tell application "Terminal" to do script "echo hello" in tab 2 of window 1'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.