3

I am trying to create a applescript which utilises the keystroke spacebar I have this code

tell application "System Events"
    keystroke {Space}
end tell

But When I play the script "space" just doesn't work. I don't receive an error message or anything (the whole code opens a recording software within the script that when spacebar is pressed recording stars but the script doesn't start the recording.)

This post shows how to hold a modifier key left shift and send it to system events, but is the syntax above correct to press the space bar?

  • This is actually a decent question, I hope you don’t mind my reopening it for some help and answers. – bmike Sep 5 '18 at 5:34
4

Your sample code works properly on my machine (running OS X 10.11.6).

If keystroke space does not work on your machine, try the following:

tell application "System Events"
  key code 49 -- space bar
end tell

Here is a list of key codes for your reference:

AppleScript key codes for keys

Source:

2
tell application "System Events"
    key code 49
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .