Applescript Keystrokes

1,337 views
Skip to first unread message

Jason Wagner

unread,
Aug 29, 2018, 6:03:33 PM8/29/18
to QLab
I am trying to tell terminal to have my Christie projector to shutter

tell application "Terminal"
set currentTab to do script ("telnet 10.0.1.45 10000")
delay 0.1
keystroke "return"
delay 0.1
do script ("C0D") in currentTab
delay 0.1
end tell

I've tested the telnet commands in terminal. They work. However, Qlab will not send the keystroke "return" properly. I receive "ERROR: Terminal got an error: Can't get keystroke "return". (-1728)

I need the return keystroke because the Christie L2k1000 wants a network password through telnet even though I haven't set one. It wants the default.

Any ideas? Suggestions? Need more info?

Wags

Rich Walsh

unread,
Aug 29, 2018, 6:32:24 PM8/29/18
to ql...@googlegroups.com
You have to invoke keystroke via System Events. If you did that you'd find that your script will type "return", not press return.

The clunky form is:

tell application "Terminal"
activate
tell application "System Events"
tell application process "Terminal"
key code 36
end tell
end tell
end tell


Is Telnet really the only option? Have you read https://groups.google.com/d/topic/qlab/6C0Hmt_Njr0/discussion?

Rich

Jason Wagner

unread,
Aug 29, 2018, 6:52:53 PM8/29/18
to QLab
I have read through that post. It's what got me going initially. I do not know yet if anything but telnet will work with the L2K1000. I'll have to try the System Events way of a keystroke first just to get it working., then I'll research a little more about other solutions. 

Thank you for the info. I will test it out tomorrow. 

Jason Wagner

unread,
Aug 30, 2018, 3:25:07 PM8/30/18
to QLab
Rich, thanks for the help. I did get it to work with the below syntax, and changing the C0D to C0E for shutter open or close. I looked into using PJLINK commands, but my Christie L2K1000 wants to have a password set all the time, so I don't know if I can get around that. I think I will reach out to Christie for other control options. 

tell application "Terminal"
set currentTab to do script ("telnet 10.0.1.45 10000")
delay 0.1
tell application "Terminal"
activate
tell application "System Events"
tell application process "Terminal"
key code 36
end tell
end tell
end tell
delay 0.1
do script ("C0D") in currentTab
delay 0.1
end tell

Currently, when I run the script, the Terminal window that opens becomes the focus and the next spacebar "GO" doesn't execute, because QLab isn't the focus. So, what I've come up with to open or reuse an open terminal window, telnet to the shutter, and hide the window is the following script:

if application "Terminal" is running then
tell application "Terminal"
do script ("telnet 10.0.1.45 10000") in window 1
delay 0.1
tell application "Terminal"
tell application "System Events"
tell application process "Terminal"
key code 36
end tell
end tell
end tell
delay 0.1
do script ("C0D") in window 1
delay 0.1
tell application "System Events"
set visible of application process "Terminal" to false
end tell
end tell
else
tell application "Terminal"
activate
do script ("telnet 10.0.1.45 10000")
delay 0.1
tell application "Terminal"
tell application "System Events"
tell application process "Terminal"
key code 36
end tell
end tell
end tell
delay 0.1
do script ("C0D") in window 1
delay 0.1
tell application "System Events"
set visible of application process "Terminal" to false
end tell
end tell
end if

While this works, I'm running into another issue. If I run the Open Shutter script, the shutter opens and the telnet session remains active for about 15 seconds. If I send the Close Shutter script during that 15 seconds, it works. However, if the telnet session times out and terminal reverts to the command line and then I run Close Shutter, the "C0E/C0D" gets typed in the password field. 
-------------------
Last login: Thu Aug 30 13:54:32 on ttys000
DCPHs-Mac-mini:~ DCPHAudioQLab$ telnet 10.0.1.45 10000
Trying 10.0.1.45...
Connected to 10.0.1.45.
Escape character is '^]'.

PASSWORD: 

Hello
C0D
telnet 10.0.1.45 10000
C0E
telnet 10.0.1.45 10000
C0D
Connection closed by foreign host.
DCPHs-Mac-mini:~ DCPHAudioQLab$ telnet 10.0.1.45 10000
Trying 10.0.1.45...
Connected to 10.0.1.45.
Escape character is '^]'.

PASSWORD: C0E
Connection closed by foreign host.
DCPHs-Mac-mini:~ DCPHAudioQLab$ 
-------------------

How can I best modify this to open terminal, or use the current terminal window, run the telnet session command, close the telnet session, and then be able to run the next one properly?

Thanks,

Wags

Jason Wagner

unread,
Aug 30, 2018, 4:43:07 PM8/30/18
to QLab
I'm trying to send scripts to quit Terminal, but I need a command to "press enter" when the dialog box comes up asking if I want to quit the process. But nothing I try in the script seems to want to work. Is there a way to respond to dialog with Applescript?

Jason Wagner

unread,
Aug 30, 2018, 4:57:11 PM8/30/18
to QLab
I came up with force killing terminal with:

tell application "Terminal"

do script ("telnet 10.0.1.45 10000") in window 1

delay 0.1

tell application "Terminal"

tell application "System Events"

tell application process "Terminal"

key code 36

end tell

end tell

end tell

delay 0.1

do script ("C0D") in window 1

delay 1

tell application "System Events"

do shell script "kill -9 " & unix id of process "Terminal"

end tell

end tell


Not exactly what I would expect, but maybe this will work well enough.

Rich Walsh

unread,
Aug 30, 2018, 6:09:55 PM8/30/18
to ql...@googlegroups.com
This will quit out of a Telnet process and then quit Terminal:

tell application "Terminal"
do script "quit" in front window
quit
end tell

I think this will open Terminal, send your commands, quit and return to QLab but I can't test it:

tell application "Terminal"
activate
do script ("telnet 10.0.1.45 10000") in front window
delay 0.1
tell application "System Events"
tell application process "Terminal"
key code 36
end tell
end tell
delay 0.1
do script ("C0D") in front window
delay 1
do script "quit" in front window -- Exit Telnet session
quit
end tell
tell application id "com.figure53.QLab.4"
activate
end tell

You may not need to quit Terminal each time, just close the Telnet session.

Rich

-- 
Contact support anytime: sup...@figure53.com
Follow Figure 53 on Twitter: https://twitter.com/Figure53
User Group Code of Conduct: https://figure53.com/help/code-of-conduct/
--- 
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/f6f2602a-3e8a-4d01-81f5-352748ea2b46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Wagner

unread,
Sep 4, 2018, 8:14:10 AM9/4/18
to QLab

Rich,


I see how that could work, but Terminal puts up a dialog box asking for confirmation of the "quit" during the telnet session. By the way, if it matters, I'm running High Sierra with QLab 3 & 4.


Screen Shot 2018-08-31 at 11.00.57 AM.png

Rich Walsh

unread,
Sep 4, 2018, 12:32:47 PM9/4/18
to ql...@googlegroups.com
That means that the first "quit" didn't exit the Telnet session. It worked when I tested it, but then I don't have anything to connect to… Maybe you need to "close" first?

The dialog appears because you aren't exiting your Telnet session gracefully before quitting Terminal. You need to work out how to do that: then Terminal won't prompt for confirmation.

Rich

On 4 Sep 2018, at 13:14, Jason Wagner <wag...@gmail.com> wrote:

Rich,


I see how that could work, but Terminal puts up a dialog box asking for confirmation of the "quit" during the telnet session. By the way, if it matters, I'm running High Sierra with QLab 3 & 4.



For more options, visit https://groups.google.com/d/optout.

Jason Wagner

unread,
Sep 13, 2018, 3:40:44 PM9/13/18
to QLab
Rich,

It seems that terminal wants a Control C command to quit the telnet session. Is there are way to type that out in a command?

What other ways besides Telnet would you suggest? I've got an email to Christie to hopefully get definite answers as to what works with this projector. 

Thank you,

Wags

hoganso...@gmail.com

unread,
Sep 14, 2018, 12:39:51 AM9/14/18
to QLab
You can insert the following into your script to cause Terminal to receive the interruption signal, inserted between your Christie command and the quit command:

tell application "System Events"

keystroke "c" using {control down}



-brendan hogan
Reply all
Reply to author
Forward
0 new messages