1

I am writing a simple (haha) bash script that will send keystrokes to an app. It uses the osacript command line to do this, like so:

osascript <<EOSCRIPT
    activate application "Mini vMac"
    tell application "System Events" to keystroke "a"
EOSCRIPT

When this script is run, it does bring the app to the front, but then I get the following error:

77:90: execution error: System Events got an error: osascript is not allowed to send keystrokes. (1002)

I have tried whitelisting /usr/bin/osascript but other search results suggest that it doesn't want this. The bash script itself is unselectable (which doesn't necessarily mean that it doesn't want it, just that I can't check).

How do I force it to let me run this? 10.14.6 Mojave if it matters.

John O
  • 4,863
  • 8
  • 45
  • 78

1 Answers1

1

I don't have Mini vMac; however, on macOS Mojave 10.14.6, the following example AppleScript code should work to send a keystroke, assuming a Mini vMac window is open, and Terminal is given permission in: System Preferences > Security & Privacy > Privacy > Accessibility

osascript -e 'activate app **Mini vMac**' -e 'delay 0.25' -e 'tell app "System Events" to keystroke "a"'

Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

user3439894
  • 7,266
  • 3
  • 17
  • 28
  • Thanks for this. I saw Terminal in there, but it had become unchecked, and I didn't notice until you posted this answer. Thanks much. – John O Jun 18 '20 at 04:47