One helpful habit when programming is to keep an eye on what actually happens after you add any unfamiliar code. The quick way to do this in AppleScript is with the result
variable. Commands' return values go to result
, but you can also explicitly set it for clarity. The value in result
is shown at the bottom of the default window in Script Editor.
For example, I pasted in just this portion of your script, with a tweak:
tell application "Terminal"
set result to open "/Users/jredfox/Desktop/h.terminal"
end tell
Execution took waaay too long, and the result
was missing value
. So right off the bat we know nothing else is going to work. But why?
I chose "Open Dictionary…" from the "File" menu, and chose Terminal. It seems Terminal uses the open
command from the Standard Suite, which means it by default wants an AppleScript path, not a POSIX path.
set result to open "Macintosh HD:Users:jredfox:Desktop:h.terminal"
Well, it opened instantly now, but even that doesn't help as result
isn't right. It seems the open
command does not return a reference to the new window, as I believe you were expecting.
Experimenting with result
s a bit more, (and reading in the dictionary that there is a return value from do script
); oh, and if you're willing to assume that h.terminal
will always open successfully in less than one second, and will therefore be window 1; I rejiggered your script to the following:
tell application "Terminal"
activate
open "Macintosh HD:Users:jredfox:Desktop:h.terminal"
delay 1
set custom to (do script "/Users/jredfox/Desktop/test.sh" in window 1)
end tell