Start iMac in Target Display Mode without dedicated keyboard
I have an older iMac which I am retiring as a display. It works well enough in target display mode, but I have keep the keyboard around just to switch it to display mode.
Is there a way to
- boot the iMac into target display mode
- start target display mode remotely, such as from the console?
Solution 1:
There are two options that I'm aware of which may meet your needs:
- Use the 1Keyboard app. This allows you to pair your computers via bluetooth and then use 1Keyboard to send the CommandF2 keyboard shortcut. It basically allows you to use one keyboard with multiple devices.
- Use VirtualKVM. This was designed specifically for people wanting to use their iMacs in target display mode, and works especially well in situations where you want to connect a MacBook to the iMac. For example, if you plug your MacBook into your iMac via Thunderbolt, this extention will automatically switch the iMac to Target Display Mode, allowing you to use your iMac as a monitor. It also switches off the Bluetooth on the iMac, freeing up your mouse and keyboard to pair with your MacBook (assuming you're using a bluetooth keyboard and mouse). When you unplug the MacBook, the iMac's Bluetooth will be powered back up and the monitor restored.
The above options should work fine. If you're a more advanced user, you could also check out this Super User question.
Solution 2:
You can start Target Display Mode via SSH from other macs in the local network.
Solution 3:
I was actually researching the same problem today and found a solution to the remote switching issue.
Apple Keyboard Emulator to switch remotely switch Target Display Mode of an iMac without a physically connected keyboard Problem What you need- Arduino Leonardo or compatible board with ATMega32u4 chip ~4-8 USD on AliExpress
- Arduino IDE from arduino.cc
- Text editor (I use Atom but any will do)
Download and install the Arduino IDE (I did this with version 1.8.12)
Step 2:Modify the Arduino Leonardo board description in /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/boards.txt
in the Arduino IDE app package to include the necessary USB descriptor to match the following:
leonardo.name=Arduino Leonardo
leonardo.vid.0=0x2341
leonardo.pid.0=0x0036
leonardo.vid.1=0x2341
leonardo.pid.1=0x8036
leonardo.vid.2=0x2A03
leonardo.pid.2=0x0036
leonardo.vid.3=0x2A03
leonardo.pid.3=0x8036
leonardo.upload.tool=avrdude
leonardo.upload.protocol=avr109
leonardo.upload.maximum_size=28672
leonardo.upload.maximum_data_size=2560
leonardo.upload.speed=57600
leonardo.upload.disable_flushing=true
leonardo.upload.use_1200bps_touch=true
leonardo.upload.wait_for_upload_port=true
leonardo.bootloader.tool=avrdude
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.file=caterina/Caterina-Leonardo.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F
leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L
leonardo.build.vid=0x05ac
leonardo.build.pid=0x0221
leonardo.build.usb_product="Apple Keyboard"
leonardo.build.usb_manufacturer="Apple Computer, Inc."
leonardo.build.board=AVR_LEONARDO
leonardo.build.core=arduino
leonardo.build.variant=leonardo
leonardo.build.extra_flags={build.usb_flags}
Step 3:
Start/restart the Arduino IDE, open an example sketch for the keyboard library (I used the Keyboard Message Send
example). Plug in the Arduino Leonardo compatible board and upload the sketch. Plug the Arduino into the iMac to be used in Target Display Mode
Create a script (here I named it switchTDM.sh
) to send the CMD+F2
keyboard command telling the iMac to switch in or out of Target Display Mode. Put this script in the user directory (/users/<USERNAME>
).
#!/bin/sh
# switchTDM.sh script
osascript -e 'tell application "System Events" to key code 144 using command down'
echo 'Sent TDM switch signal.'
Modify the script to be executable:
chmod +x switchTDM.sh
Step 5:
Enable SSH access to the TDM iMac by enabling "Remote Login" in the sharing options of the System Preferences. And test whether you can login from a remote machine using:
ssh <USERNAME>:<PASSWORD>@<IP or hostname of iMac>
Step 6:
Bind the call to the remote script to a keyboard shortcut. I use BetterTouchTool: Add a new keyboard shortcut and execute the following terminal command:
ssh <USERNAME>:<PASSWORD>@<IP or hostname of iMac> ~/switchTDM.sh
That's it
Use your defined keyboard shortcut to switch your iMac in and out of Target Display Mode.