Search code examples
macosapplescriptkeyboard-shortcutsfinder

How to make finder run a keyboard shortcut in applescript?


This is my current code:

tell application "Finder"

    tell application "System Events" to keystroke "k" using {command down}

end tell

But it won't work.

Any tips?


Solution

  • You do not tell the Finder to tell system events to do stuff.

    You need to just make sure the Application that you want to intercept the keystrokes is active. Then tell System events to do the keystroke.

    tell application "Finder" to activate
    tell application "System Events"
    
        keystroke "k" using {command down}
    
    end tell