r/applescript • u/5-fingers • May 18 '22
Help me with this script please!
So I'm trying to create a bit of apple script that will execute a keyboard shortcut on a remote computer (over a network). The shortcut is shift+Cmd+n. The application is called Timax2
Ive got as far as the script shown in the image.
........ But when I run it I get the syntax error "Application isnt running"..... I know the obvious question is "is the application running on the remote computer?!" And, Yes it is.
The script works if I run it on locally with the app on the same machine the script is run from (removing the "of machine "eppc://10.0.0.33"" bit)
I know the networking connection is ok as I can run a script to "tell "finder" of machine "eppc://10.0.0.33" sleep"
So any suggestions?
View all comments
Show parent comment
2
u/ChristoferK Jun 02 '22
I am specifically talking about key strokes (by way of either the
keystrokeorkey codecommands) and what I’ve stated remains true. Other commands work in their own individual manners, which include those that will either permit or require a targetUI Elementclass object to act upon (of whichprocessobjects are a subclass). For example:selectmust be given a target element; whereclickcan optionally accept a target element, or, alternatively, it can be given a pair of coordinates{x, y}for its"at"parameter.keystroke,key code,key down, andkey updo not accept a specific target. When aprocessis targeted using one of these commands, AppleScript silently ignores this, and refers the command up the inheritance chain to the System Eventsapplicationobject, which will be what is happening when UIBrowser and Script Debugger (erroneously) target aprocess.Here's a simple test you can perform:
The main part of the script is the
tellblock targeting System Events, which loops through every runningprocessand sends thekey codeinstruction to eachprocesssequentially...well, it attempts to, but as stated above, this can't happen. To visualise this, the lines before and after thetellblock ensure the open document from which the script is executing can effectively display anykey codeinstructions received by the frontmostprocessto which the open document belongs, tallying up the total number of"#"characters output, which you'll be able to compare with the total number of running processes.For a more introspective look at whether there's scope for these
key...commands to target processes, we can turn to JXA, which is less forgiving when commands target an object that doesn't implement it: it will either return anundefinedresult or throw a demonstrable error in cases where AppleScript will do a little bit of grunt work and try a few sensible alternatives. If AppleScript didn't do this, all of your scripts where you target aprocesswithkey...commands would choke:This wouldn't have been fixed by targeting the process, but by some other consequence that resulted by the edits made that were subtle but significant, and made it seem on first glance to be the result of process targeting. This sort of misinterpretation when debugging and changing scripts happens all the time.