# start.sh
osascript -e 'tell application "System Events" to key code 144 using command down'
echo " 🖥 Target Display Mode Started..."
blueutil off
echo " 🔵 iMac Bluetooth off..."
exit
# end.sh
sleep 5
blueutil on
echo " 🔵 iMac Bluetooth on..."
sleep 5
echo " 🖥 Target Display Mode command..."
osascript -e 'tell application "System Events" to key code 144 using command down'
echo " ✅ Target Display Mode Ended..."
exit
Put start.sh
& end.sh
in your iMac.
SSH into your iMac.