# 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.