2

I'm trying to use Automator with AppleScript to automatically hit Command + F2 to enter Target Display Mode. The script runs but I just get a beep/tone with no action. I don't know if there's an error in the script or if it's not capable of hitting a function key.

on run {input, parameters}

    tell application "System Events"
        key down {command}
        keystroke "120"
        key up {command}
    end tell
return input
end run

Once I get this working I'll need to somehow schedule this to run on startup or maybe on a schedule. I've seen some threads on this but never an actual solution. I'm using a 2011 iMac as a secondary monitor and hate hitting Command + F2 every day.

1 Answer 1

2

keystroke "120" is not the same as key code 120; the former taps the keys 1, 2, and 0.

I've had success with the following AppleScript, but you can also try key code 120 and key code 113.

tell application "System Events" to key code 144 using command down
1
  • That's awesome! Worked great. I converted the service to an application and set it to run as a login item. Thanks so much for the help!
    – Greg
    Commented Jun 20, 2019 at 18:53

You must log in to answer this question.

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