how can I script a shortcut for command-F2 (target display mode)?
how can I script a shortcut for command-F2 (target display mode)?
iMac, OS X Mavericks (10.9.2)
how can I script a shortcut for command-F2 (target display mode)?
iMac, OS X Mavericks (10.9.2)
To clarify context: My TDM works fine. However, when working remotely, if there is a power interruption at the office and machines reboot, I will not be in TDM (and there are other ways this could happen also - all of them end up with me away from the office and the iMac not in TDM where I need it). When this happens it will be necessary to have a method of sending the command-F2 from the remote machine. This is apparently impossible - only a connected keyboard can generate a Command-F2 that can throw the iMac into TDM.
One of the Apple geniuses suggested setting up a desktop script with a shortcut that will issue the Command-F2 when clicked even from the remote machine. However, when I try to set up the script, the Command-F2 does not seem to be recordable (or enterable) in the script. If I try to record the command while writing the script it just pops my iMac right into TDM. In using scriptwriter I don't know the syntax to actually instruct the script to issue a Command-F2 and there seems to be no documentation on this procedure. I have searched Help for Script Commands, including those for Terminal. Anybody have any ideas on this somewhat obscure but real dilemma?
PS - I am aware of the possible work-around of using virtual desktops on the MBP instead of actual displays on the MBP and iMac when I am remote.. However, I use LogmeinPro to access remotely. The Logmein solution toggles (elegantly) through multiple screens, while the BacktomyMac implementation is cludgy in many ways that make it unusable for remote work. (BacktomyMac also cannot address the TDM command situation.) In consequence, the virtual desktop work-around is not a good solution. Similarly, another proposed work-around I have heard is to use Target Disk Mode instead of Target Display Mode and use the MBP disk for the iMac display, thus giving up remote access to the MBP 15" display. This too is a less than perfect solution for the obvious reason that, again, there is then less display real estate. Hoping some very creative experts are out there who have a good idea for a true work-around or else know how to pass the Command-F2 from an object on the desktop rtather than the local keyboard. Hope you can help -- Perplexed Staminac!
Try this Applescript:
tell application "System Events"
key code 122 usingcommand down# Cmd-F2
end tell
for example, by SSH-ing into your iMac. Execute a local script performing e.g. the SSH call on your Macbook using Butler, LaunchBar, Alfred, Quicksilver, Keyboard Maestro, or any of the other, similar tools, or simply the Services menu/Automator.
from: http://superuser.com/questions/226880/send-key-combination-via-local-network-to- other-mac
You should be able to just ssh to the remote Mac and then enter:
osascript -e 'tell application "System Events" to key code 122 using command down'
That source may be wrong, try key code 120
osascript -e 'tell application "System Events" to key code 120 using command down'
Better yet, add this to the .bash_profile on your remote Mac:
function tdm() {
osascript -e 'tell application "System Events" to key code 120 using command down'
}
Then, when you ssh into the remote Mac, all you need to do to is enter: tdm
Or if you use a remote desktop, then enter in Applescript Editor:
tell application "System Events" to key code 120 usingcommand down
and save as an App that you can click.
Hi guys!
I just got an iMac 2009 to use as a second screen to my iMac 2013. I tried both the bash-variant and the apple script variant, but none of them work. Both result in an error chime and nothing else happens.
Is it working for you guys?
Cheers,
Kim
Hi!
I was a bit unclear. TDM itself is working fine for me, but only when triggered from the physical keyboard. The send keys -approach does not work as suggested in the above code examples.
Cheers,
Kim
The following was derived from Jose's post here on superuser. Notice that Jose uses keycode 144 but I have no idea why, as 120 is the F2 key on Mac keyboards.
On the iMac where you want to switch into Target Display Mode, put the following script in your home/bin directory. Make it executable. call it tdm.sh.
#!/bin/bash
#
osascript -e "tell application \"System Events\" to key code 120 using command down"
exit 0
Remotely, you would trigger TDM as:
ssh username@target-display-machine "~/bin/tdm.sh"
Hi!
That doesn't work either. The script itself runs, but only produces the audible error chime. All three methods behave identically.
Cheers,
Kim
Hi again!
Got it. 144 works. 120 doesn't. Go figure...
Thanks for the help!
Cheers,
Kim
Good.
Always boot the second Mac in TDM (you only have to do this when you reboot your second Mar, afterwards you forget your second, dedicated keyboard and mouse goodbye). Once TDM is established, get the utility Screen Sharing Menulet (two or three bucks), go to its Preferences and tick the Launch on Startup option. Then use it to launch SSH to operate your second Mac as a separate computer. When you want to get reclaim your second Mac as a simple,external screen, just go to Dock, find the SSH icon, and use it to open a tunnel to your new Mac.Once your SSH connection is established, keep it on and dodge in our of using your second Mac independently by showing or hiding SSH via its Dock menu.
TDM is nice idea, but Apple could make it a lot better by a.) creating a way for a Maq to boot into TDM, and b.) allowing one to open/close a TDM connection by issuing simple keyboard commands on his primary compute, eliminating that silly and very un-Mac-like need for a second keyboard and pointing device.
B. t. w.,I recenty noticed tha rejiggered Apple rejiggered SSH, so now you can cut-and-paste data and pass files and folders by drag-and-drop bewten linked Macs. This was a long time coming/ Apple. Thanks, it's a big step forward
Can confirm that in this case, key code for F2 is actually 144
Thank you johnssonkim - this was the missing link.
how can I script a shortcut for command-F2 (target display mode)?