3

Im looking to send a key press to a background application using AppleScript modules within a keyboard maestro macro. I would like one module to send key down to app and another module to release the key to background application.

I have tried keyboard maestro built in functionality to do this, I have read elsewhere about AppleScript features which seem to allow this functionality but im not very advanced with AppleScript so some help would be appreciated!

Tobias
  • 31
  • 4
  • Can you specify what app you're trying to send the key press to in the background, and what you're trying to achieve? e.g. dismissing an alert, entering text, pressing a button... – Ted Wrigley Aug 01 '19 at 20:42
  • Tobias, so generally speaking, AppleScript **cannot** send keystrokes to a background process, and for vanilla AppleScript, this is always true, as _System Events_ only ever targets the active window of the frontmost process. It's possible to do it using Objective-C methods, but they use data types that don't bridge to an AppleScript equivalent (i.e. AppleScript has no way to understand the data being sent and received). Therefore, the only way I can think of doing this would be to use the ObjC bridge from another language, e.g. JXA, Python, Swift, etc. Though someone may prove me wrong. – CJK Aug 01 '19 at 21:52
  • @CJK: It's true that keystrokes get picked up by the frontmost window, but thee are workarounds — such as setting the value of a UI element or performing an action — that will work in the background. That's why I'm trying to clarify what he's doing. – Ted Wrigley Aug 02 '19 at 02:09
  • the application is a game with no UI elements which can be scripted, so all I need is a keypress – Tobias Aug 02 '19 at 07:25
  • the other scripting modules available in keyboard maestro are execute shell script, execute swift script, execute javascript for Automation, execute javascript in all custom prompts. hopefully one of these could be more accessible? – Tobias Aug 02 '19 at 07:35

0 Answers0