So I'm trying to make a script that holds down a key like Left option. But I don't want to use something like

tell application "x"
    keystroke *keycode*
end tell

I tried doing that, but the app I'm trying to make it work for won't accept it. So I thought of trying to make a script that just holds down a key (specifically a modifier key) for an indefinite time.

Is there any solution?


2 Answers 2


Try running your code using the key down & key up features of AppleScript.


tell application "System Events"
    key down option
    delay 5
    key up option
end tell

keystroke is actually part of the application "System Events, so try something like this:

tell application "x" to activate
delay 1
tell application "System Events"
    tell process "x"
        repeat n times
            keystroke "keycode"
        end repeat
    end tell
end tell

Where x is the application/process and n is a number.

  • 1
    Please, don't guess! Your script simply repeats keycode n times, but doesn't hold down a key!
    – klanomath
    Commented Dec 8, 2016 at 4:13

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