Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MichaelQuick232

macrumors newbie
Original poster
Oct 14, 2011
14
0
Hello all!
I'm relatively new here, and to AppleScript. However, I'm tryiong to get terminal to do this

(Script Starts)
1)open terminal
2) enter command "heyu off A2"
3) hit "return"
4) wait 3 seconds
5) close terminal

I currently have this script, but it's not seem to working.

tell application "Terminal"
activate
keystroke heyu off A2
keystroke (ASCII character 13)
delay 3
quit
end tell


any help?

thanks!

--Mike
 
Hello all!
I'm relatively new here, and to AppleScript. However, I'm tryiong to get terminal to do this

(Script Starts)
1)open terminal
2) enter command "heyu off A2"
3) hit "return"
4) wait 3 seconds
5) close terminal

I currently have this script, but it's not seem to working.

tell application "Terminal"
activate
keystroke heyu off A2
keystroke (ASCII character 13)
delay 3
quit
end tell

any help?

There are two reasons it's not working:

keystroke must be issued through System Events
keystrokes themselves must be enclosed in quotes, otherwise the system will assume that you mean to issue the command keystroke heyu off A2 and, obviously, it won't understand.

Try this:

Code:
tell application "Terminal"
	activate
	tell application "System Events"
		keystroke "heyu off A2"
		keystroke return
	end tell
	delay 3
	quit
end tell
 
There are two reasons it's not working:

keystroke must be issued through System Events
keystrokes themselves must be enclosed in quotes, otherwise the system will assume that you mean to issue the command keystroke heyu off A2 and, obviously, it won't understand.

Try this:

Code:
tell application "Terminal"
	activate
	tell application "System Events"
		keystroke "heyu off A2"
		keystroke return
	end tell
	delay 3
	quit
end tell

Thanks!! It worked like a charm. the only thing is, after it says "quit" after i turn it into an application in the Save As... and when I run it, it brings up a dialog box that says
"Connection is invalid." (to the terminal) how do i get it to close that box at the end of the script too?

--Mike
 
You should look up the AppleScript command do shell script.

Example:
Code:
do shell script "heyu off A2 ; sleep 3"


On the larger question, you can't tell an application to quit within a tell/end tell block. The reason is that quit breaks the connection by quitting the application, but the tell block needs a connection. It's like telling someone you're talking to on the phone, to hang up the phone then you'll tell them what to do next. Catch-22.

To tell an application to quit, you must use the one-line form:
Code:
tell app "Terminal" to quit
and it must be outside the tell/end block of any other communications with that app.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.