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.

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
add comment

1 Answer

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
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.