r/applescript • • 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?

3 Upvotes

12 comments sorted by

View all comments

Show parent comment

2

u/ChristoferK Jun 15 '22 edited Jun 15 '22

That would fail because the process receiving the UI commands must be frontmost. I'm sure we agree on that point.

Essentially, yes, I agree, at least with the conclusion if not the semantics. You’re suggesting there’s a condition on the process you wish to receive the UI commands (key stroking commands) that it necessitates it being the frontmost process; I’m asserting that there’s no such condition being tested, and keystroking commands are simply sent directly to whichever process is frontmost.

My test code also demonstrates this, by targeting processes that aren’t frontmost, while visualising the receipt of the command in the process that is frontmost. Your suggestion that a “failure” occurs isn’t supported from what I can see.

The correct format for a UI scripting command is:

It’s more helpful if we maintain the distinction made from the outset, so it’s clear that this discussion pertains only to the keystroking set of commands, not UI commands in general. As I detailed before, some UI commands can act on a specific process that need not be frontmost (eg. click).

If you omit the "tell process ..." then, yes, System Events will resolve it, but that will take longer and may require timeouts and may still cause the command to fail.

Where did you learn this ? If you can point to a specific source, this might help clear things up for us both. Certainly, I would like to know if I am wrong. But nothing that Script Editor or Script Debugger outputs, nor any documentation I’ve seen, suggests that System Events attempts to “resolve” anything in the case of an absent target process. Without unwrapping the apple event message itself, it fully appears that keystroking commands targeted at a specific process are what require resolving in order to retarget the command to System Events directly.