Automator and/or AppleScript to automatically Command-F2 to enter Target Display Mode
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.
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