Here's my setup: MacBook --> Thunderbolt Display --> iMac 27"

The MacBook is the primary computer I want to use; the iMac is the (external) display.

This all works just fine. The problem is, when I disconnect and then reconnect the MacBook, I have to manually put the iMac in Target Display Mode using the keyboard. This means I need to keep a keyboard attached to the iMac, and it clutters up my desk!

Is there any way to switch the iMac into TDM without using the keyboard? Maybe by logging in remotely?

I found a few similar questions, but... no answers!

Is it possible to have an iMac maintain target display mode even through sleep/screensaver

Target Display Mode: how to automate and persist on closing laptop


  • 3
    osascript -e 'tell application "System Events" to key code 144 using command down' worked for me in Mavericks, but hasn't worked since updating my iMac to Yosemite. :|
    – Danica
    Commented May 5, 2015 at 20:22
  • 1
    @Dougal, I just tried it and it worked on 10.10.4.
    – gk5885
    Commented Aug 19, 2015 at 15:26
  • The osascript approach only works when there is a keyboard plugged in. Commented Mar 12, 2017 at 22:06

5 Answers 5


I found a way to do it with an old, white apple keyboard, haven't tested with others but it might work.

I used a tool called Karabiner from https://pqrs.org/osx/karabiner/. When you install it, enable following options to get Command + F2 to work:

F1..F12 to Functional Keys (Brightness Adjust, Music Control, etc)
- F1,F2 to Brightness Adjust
--- F1 to Brightness Down
--- F2 to Brightness Up

After enabling this option, hit Command + F2 having previously connected your macbook using thunderbolt cable. If you're lucky you'll have a new external display working!

  • Karabiner fixed my problem, but not the specific one Stanislaw listed, it was the option listed under "For PC Keyboards" that worked in my case. There are many "F1..F12" options listed and you might need to try many of them before finding one that works. Commented May 28, 2015 at 22:39
  • This worked great for me with a non-Apple keyboard. Commented Jun 21, 2016 at 1:30
  • Are you able to provide exact values of your configuration? Cmd+F2 not working for me on 3rd party keyboard w display_brightness_increment/display_brightness_decrement. I've read you must use apple keyboard but I thought there was a way around it.
    – danronmoon
    Commented Dec 8, 2019 at 21:19
  • @stanislaw Man! you saved my life! Tried different approaches all across the internet, nothing worked! But his thing just saved my life! :D Thanks a ton bro! Commented Sep 26, 2020 at 12:00
  • @stanislaw, can you please elaborate how karabiner eliminates the need for a keyboard: when you say "hit command F2" - do you mean w/o keyboard by using the karabiner ? I did not find the option to do it inside the app... Thanks!
    – Alex Levit
    Commented Apr 7, 2023 at 11:19

VirtualKVM will allow you to use your "iMac as a monitor for [your] Macbook". This is super easy and free.

  • Just to say thanks, this is a very useful app! I'm also trying out 1Keyboard. Commented Dec 6, 2017 at 11:50

I was in that situation some time ago. The only way that seems to work without issuing the shortcut with Apple keyboard I found was this in Logitech forums.

I have successfully implemented what I believe is a reasonable workaround. Here's what I did...

Purchased and installed Keyboard Maestro from Stairways Software.

Within Keyboard Maestro I created a new Macro in the Global Macro Group.

For "Triggered by any of the following:" I selected "This device key:" and then hit the mute button (i.e. F10) on my Logitech keyboard. Keyboard Maestro correctly captured this as "USB Receiver Mute".

For "Will execute the following actions:" I had Keyboard Maestro record my keystrokes and then I hit ;-F2 USING MY APPLE KEYBOARD. Keyboard Maestro captured this as -? (I'm sure the ? is just a place holder). It looks odd, but it works.

Now when I hit the mute button (F10) I can enter AND EXIT Target Display Mode from my Logitech keyboard.

I originally tried another key (F15), but that didn't work for me. It allowed me to enter, but not exit, Target Display Mode. I suspect that this is due to the fact that your Mac ignores most all of the keys on the keyboard when in Target Display Mode. However, I knew it still "listened" to the keys that control music playback. I selected mute as it was the least offensive to use. I haven't tried any others yet.

But, this method as the author says in his following post, have a really nasty disadvantage:

Turns out the solution isn't perfect. After I took the batteries out of my Apple wireless keyboard, the mute/F10 trick on the Logitech keyboard stopped working. So, now I have the Apple wireless keyboard turned on, but not in use - the mute/F10 trick on the Logitech keyboard works again.

So, It's a pity, but the best method is to maintain and use the Apple keyboard.

  • I tested this solution and it works great if you're already using Maestro. The Karabiner option however doesn't require an apple keyboard (Karabiner is also free). Commented May 28, 2015 at 22:42

Just a followup in case anyone still has problems even with the previous instructions. To my knowledge, this only applies to Logitech keyboards, although it might apply to others that have software (i.e. Logitech Control Center) controlling the functionality of the Function keys.

In this case, the software controlling the keyboard overrules Karabiner - in Logitech Control Center (LCC) this can be "fixed" by going to the "General" tab of the LCC keyboard settings and check the first checkbox: "When this box is checked, press F1, F2, etc. keys to use the standard function keys, and press and hold the Fn key to use the enhanced functions printed on the keys."

After checking that box the function keys are annoying to use - as it says you have to press them in conjunction with the "fn" key. BUT target display mode works like a charm if you've enabled F1/F2 brightness controls in Karabiner! As I use it rarely, I just leave the box unchecked so that the keyboard is more user friendly and then check it when I want to use TDM!

Hope this is helpful!


Generally, I'd add the possibility to control the imac via screen sharing.

1. enable screen sharing on the imac

2. reboot imac without mouse/keyboard, wait at login (or enable autologin)

3. connect macbook via thunderbolt, start macbook, connect keyboard to mac (via usb or bluetooth)

4. locate imac in macbooks finder, enable screen sharing

5. press ⌘ Cmd+f2 or fn+⌘ Cmd+f2 on your keyboard connected to your macbook

6. voila!

That does not seem to work reliable enough. Or at all... but the first line stands true, if someone figures that F2 command out, i'd still recommend screen sharing....!

  • Why are your lines crossed-out? This answer doesn't make much sense as it's currently written.
    – fsb
    Commented Jan 24, 2020 at 12:28
  • you are right, the crossed out lines do not RELIABLY work, so it is not a working solution, although someone might find out how to use the screen sharing feature correctly!
    – valtheuw
    Commented Jan 28, 2020 at 10:47
  • If it's not a solution, it shouldn't be added as an answer. You risk downvotes, which impacts your site reputation, with this type of answer. See How to Answer for important info.
    – fsb
    Commented Jan 28, 2020 at 13:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .