Sending Keystrokes to Inactive Applications with Applescript

I'm fairly new to AppleScript. It's a strange language which seems too complex for non-programmers and and too cute for programmers but I'm trying. Right now, I'm trying to figure out how to send a keystroke to an inactive instance of Keynote, without activating it. Got to be something about finding the appropriate widow and sending a keystroke to that. I'd like to send Fn+DownArrow. Anyone know offhand how to pull that off? Thanks!

Jonathan


MacBook Pro with Touch Bar

Posted on Jul 25, 2020 4:53 PM

Reply

Similar questions

6 replies

Jul 25, 2020 6:46 PM in response to JVZuck

Sending keystrokes is done through System Events, not to any app. System Events sends the keystrokes to the active process.

Another shortcoming for you is there isn't a "fn key down" modifier in the keystroke command, only command, control, shift, and option.


Normally, you would just tell the app to do something, not send it keystrokes, but if the Keynote dictionary doesn't support whatever command you want to execute, you would need to send keystrokes.


Jul 25, 2020 7:12 PM in response to Barney-15E

Thanks. Yes, Keynote dictionary supports advancing the slides, which is what I want to do, but it requires you to first activate Keynote to accept the command, unlike PowerPoint. The trick is that I'm trying to advance the slides withOUT activating Keynote. So what I need to do instead is send a keystroke to the window, which I know works because I got it to work in Keyboard Maestro. I can also send PgDn/PgUp to navigate the slides. Does that help?

Jul 25, 2020 7:26 PM in response to JVZuck

There is also a key code command, but you would need to figure out what PgUp and PgDn codes are. Again, it is sent to the active process, so likely wouldn't work, either.

https://dougscripts.com/itunes/itinfo/keycodes.php


Are you trying to advance the slides while it is not playing?

show next and show previous advance and backup the slides while the show is playing. I couldn't find anything to move to the next slide while it is not playing.

Jul 25, 2020 8:18 PM in response to Barney-15E

Thanks. It's a strange use case but has to do with using broadcast software, that allows you to switch between cameras, applications, videos, etc., as part of a Live stream or a recording. Essentially, I would like to be able to advance a Keynote presentation, that IS running, without bringing that presentation to the foreground. Again, I've been able to confirm, using Keyboard Maestro, that it is possible so it's just about finding the window, of the current process, of the keynote application and sending a key to it. Lots of AppleScript objects have the keystroke method but I need to get a reference to the current Keynote application window (when I slideshow is running) and send a keystroke to that.

Jul 25, 2020 8:50 PM in response to JVZuck

I'm not aware of a way to do that as I always thought System Events just sent the keystroke to the frontmost process. Maybe there is a way to tell System Events to send it to a certain process.

I'm working on a single monitor at the moment, so I have no way to have keynote playing a slideshow and then run an AppleScript. I can't really try out anything.

System Events is aware of processes, so you may be able to direct it at a process.


If the Slideshow is playing, can you just tell application "Keynote" to show next?

Jul 25, 2020 8:56 PM in response to Barney-15E

It turns out, you cannot. The commands in the keynote dictionary require keynote to be in front, ie activated. So I need to send a keystroke either to the process or the window, which appears to be Window 1 so that helps.


I'm a single monitor as well but Keynote now allows you to play your slideshow in a window instead of a full screen, so that's what I'm doing. You go to the Play menu to do it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Sending Keystrokes to Inactive Applications with Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.