Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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)

Posted on Mar 1, 2014 11:04 AM

Reply
14 replies

Mar 1, 2014 12:17 PM in response to staminac

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!

Mar 1, 2014 1:43 PM in response to 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'

Mar 1, 2014 2:35 PM in response to staminac

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.

Mar 8, 2015 10:39 AM in response to johnssonkim

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"

Jun 30, 2015 5:22 AM in response to staminac

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

how can I script a shortcut for command-F2 (target display mode)?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.