I woule like my Applescript to do the following:
- pre-emptively launch the terminal WITHOUT opening up a Terminal window.
- Run other custom AppleScript Code (hmm. This is where the real work occurs)
- Then open up a Terminal window, send some commands (or a get it to execute a Bash Script) and set a custom title for the Terminal window.
- After the Terminal has finished executing the commands or script, I would like to automatically close the window after a 5 sec delay.
I have found that “Tell application “Terminal” to launch” does not really work like in other applications. If the Terminal is NOT already running, the launch command creates a new Terminal window. I had to write some custom code below to acheive the result I wanted. (i.e. Launching the Terminal without opening up a Terminal window).
I also found that AppleScript does NOT tell you when the Terminal has finished executing the commands you send to it. I had to use the “busy” property to check if the Terminal was finished. I am unsure whether the “busy” property is a reliable indicator.
Is there a better way to acheive what I want? Am I missing something?
Rob
– preemptively launch Terminal
tell application “System Events”
try
tell application process “Terminal”
get every window
end tell
on error
tell application “Terminal”
run
close window 1
end tell
end try
end tell
– Create new Terminal Window, Send commands and set Custom Title for Window
tell application “Terminal”
do script “cd Documents;ls”
tell window frontmost
set custom title to “I Hope This Works”
set title displays shell path to false
set title displays custom title to true
end tell
end tell
– Close Terminal Window when Done
try
tell application “Terminal”
repeat
tell (window every window whose name is “I Hope This Works”)
if not busy then
delay 5
close
exit repeat
else
delay 1
end if
end tell
end repeat
end tell
end try
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)