Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I use applescript to execute a script in a new terminal window and then close the window?

After the line:

set x to do script ""

Is there a way to get a reference to the window of tab x? A reliable way - not something like "frontmost window".

share|improve this question

do script returns the tab the script was run in:

tell application "Terminal" to do script ""
result -- tab 1 of window id 6166 of application "Terminal"

I don't know any way to close the tab or get its window though. window 1 should refer to the window opened by do script:

tell application "Terminal"
    do script "sleep 2; logout"
    tell window 1
        repeat until processes of selected tab is {}
            delay 0.01
        end repeat
        close
    end tell
end tell

If others were looking for how to run do script again in the same window:

tell application "Terminal"
    do script "uptime"
    do script "uptime" in result -- or window 1
end tell
share|improve this answer
    
I want to find a way that won't generate an error, but using window 1 could result in errors, so I was hoping for a way around that. – Rebecca Apr 19 '13 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .