How to trigger Target Display Mode with no Keyboard

After years trying to do this with no luck. Finally figured it out when I was looking at the xml output for a Keyboard Maestro Macro. This worked on an iMac 21" 2011 running Monterey.

↓ This is the System command for anyone who's still interested: ↓

tell application "System Events"
-- Press % key (trigger)
key code 118
-- Simulate BRIGHTNESS_UP (action)
key code 144 using control down
end tell

↓ Or you can save this in a Bash file (tdm.sh): ↓

osascript -e 'tell application "System Events" to key code 118' # Press % key (trigger)

osascript -e 'tell application "System Events" to key code 144 using control down' # Simulate BRIGHTNESS\_UP (action)

Follow the "How-to" SSH into your iMac with no password so you can trigger the command from your main machine. I'm using Raycast.↓ ↓

ssh username@imac.local "zsh ~/tdm.sh"

https://web.archive.org/web/20180815120109/https://danielpataki.com/target-display-mode-remotely/

submitted by /u/fjones1979
[link] [comments]