Skip to content

Conversation

@FreekMank
Copy link

Use iMac as external monitor by using the powerbutton to toggle TDM mode.

@Lumipyry
Copy link

Lumipyry commented Sep 16, 2025

Thank You for this, FreekMank!!!

Got this working between two iMac's: a 2011 21" as computer (Debian Trixie Gnome) and 2010 27" as monitor (KDE Neon). Earlier I tryed Debian Bookworm in monitor, but it worked only partially.

KDE Neon did not find the acpid-support package, but this did not affect at all.

I include here step-by-step installation instructions (for both smc_util and your powerbutton support), since it was and is altogether a quite complex procedure to get everything right...

I also wrote an Unix-Linux question where the following is repeated.


1.Download smc_util to home directory:

$ git clone https://github.com/floe/smc_util.git


2.Change to smc_util:

$ cd smc_util


3.Compile SmcDumpkey with GCC:

$ gcc -O2 -o SmcDumpKey SmcDumpKey.c -Wall


4.Create files tdm_toggle.sh, powerbutton, powerbutton.sh and rc.local:

$ touch tdm_toggle.sh powerbutton powerbutton.sh rc.local


5.Change content of tdm_off.sh:

#!/bin/bash
rm -f tdm_started
./SmcDumpKey MVHR 0
sleep 1
./SmcDumpKey MVMR 2
sleep 2
DISPLAY=:0.0 xrandr --output eDP --auto

6.Change content of tdm_on.sh:

#!/bin/bash
./SmcDumpKey MVHR 1
sleep 1
./SmcDumpKey MVMR 2
sleep 2
DISPLAY=:0.0 xrandr --output eDP --off
touch tdm_started


7.Create content to tdm_toggle.sh:

#!/bin/bash
pushd $(dirname "${BASH_SOURCE[0]}")

if [[ -f "tdm_started" ]]; then
  echo "Switching off TDM"
  source tdm_off.sh
else
  echo "Switch on TDM"
  source tdm_on.sh
fi

popd


8.Create content to file powerbutton:

event=button/power PBTN
action=/etc/acpi/powerbutton.sh


9.Create content to file powerbutton.sh.
REMEMBER TO CHANGE XXXXXXXXX to your username (in TWO LINES in the script):

#!/bin/bash

pushd $(dirname "${BASH_SOURCE[0]}")

FILE=powerbutton_pressed
NOW=$(date +%s)

if [[ -f "$FILE" ]]; then
  # Read timestamp of previous powerbutton press from file
  echo "File exists"
  typeset -i PREV=$(cat $FILE)
  echo Compare $NOW and $PREV

  # if two powerbutton presses were <1 seconds apart -> shutdown
  if [[ $(($NOW-$PREV)) -lt 2 ]]; then
    # Shutdown
    echo "Powerbutton pressed twice in a row: Shutting down"
    shutdown now
  else
    echo "Toggle TDM"
    /home/XXXXXXXXX/smc_util/tdm_toggle.sh &
  fi
else
  echo "Toggle TDM"
  /home/XXXXXXXXX/smc_util/tdm_toggle.sh &
fi

echo $NOW > $FILE

popd

10.Create content to file rc.local.
REMEMBER to change XXXXXXXXX to your username:

#!/bin/bash

# Start Target Display Mode such that the pc is used as external monitor right away
# Note: The Power button toggles TDM (see /etc/acpi/events)
pushd /home/XXXXXXXXX/smc_util
./tdm_on.sh
popd

11.Change to root :

$ su -l


  1. Remove the SMC kernel driver to avoid conflicts (# means root)

# rmmod applesmc


13.Make tdm_toggle.sh, rc.local and powerbutton.sh executable (change XXXXXXXXXX):

# chmod +x /home/XXXXXXXXX/smc_util/tdm_toggle.sh /home/XXXXXXXXX/smc_util/rc.local /home/XXXXXXXXX/smc_util/powerbutton.sh


14.Install build-essential and acpid:

# apt install build-essential acpid acpid-suppport


  1. Copy file powerbutton to /etc/acpi/events (change XXXXXXXXXXX):

# cp /home/XXXXXXXXX/smc_util/powerbutton /etc/acpi/events


16.Copy file powerbutton.sh to /etc/acpi (change XXXXXXXXX):

# cp /home/XXXXXXXXX/smc_util/powerbutton.sh /etc/acpi


  1. Copy file rc.local to /etc (change XXXXXXXXX):

# cp /home/XXXXXXXXX/smc_util/rc.local /etc/rc.local


  1. Restart acpid

# systemctl restart acpid

@kamranvakil
Copy link

kamranvakil commented Oct 10, 2025

Tried this set of instructions and it worked like a charm! One thing I will add is that you need to disable the Power Button in Ubuntu Settings -> Power -> General for the iMac. If you don't, switching between Target Display mode and the iMac itself will cause it to power off/suspend after a minute.

Edit: I did this with a late 2009 iMac on Ubuntu 24.04, working as a monitor with a Optiplex 7071 running Ubuntu 24.04

@Lumipyry
Copy link

Lumipyry commented Nov 9, 2025

Tried this set of instructions and it worked like a charm! One thing I will add is that you need to disable the Power Button in Ubuntu Settings -> Power -> General for the iMac. If you don't, switching between Target Display mode and the iMac itself will cause it to power off/suspend after a minute.

Edit: I did this with a late 2009 iMac on Ubuntu 24.04, working as a monitor with a Optiplex 7071 running Ubuntu 24.04

@kamranvakil

Actually I get a blanc screen with tdm_off.sh with my own instructions. So I can not get it to work perfectly.

Can you confirm the tdm_off really works in your machine?

I've tried Debian 12 and 13 KDE Plasma and Linux Mint 22 Cinnamon in the monitor machine, not Ubuntu (but Mint is supposed to be as Ubuntu)

EDIT: I thought I had it working and maybe it even worked - but after I re-installed an OS to monitor/display - machine, I could not get it working anymore...

@FreekMank
Copy link
Author

I'm still using the scripts to switch TDM using the power button (which call tdm_on.sh and tdm_off.sh), but I've never bothered to upgrade my Ubuntu installation, so I think I'm still running 20.04.
Perhaps in Debian the OS powerbutton setting is causing problems as well, similar to what @kamranvakil reported?

@Lumipyry
Copy link

Lumipyry commented Nov 11, 2025

@FreekMank
Thank You for the reply,

Perhaps in Debian the OS powerbutton setting is causing problems as well, similar to what @kamranvakil reported?

This is not the case. I could not get the thetdm_offworking even with ssh:

mint@monitori:~/smc_util$ sudo ./tdm_off.sh
type="flag" length=1 flags=c0
data="\x01"
target value: 00
type="ui8 " length=1 flags=c0
data="\x00"
target value: 02
send_byte(0x02, 0x0300) fail: 0x00
MVMR: write data fail

write_smc get_key_data error

This is similar as in issue #15 .
Actually the ssh sommand gives the same error also with tdm_on but it still works...

I'm starting to think that the tdm_off only works in iMacs from 2009 to mid-2010...

I have a 2010 model but perhaps it is late 2010 and Apple changed their SMC utility, issue #3.
Also my main machine is iMac 2011 and it uses Thunderbolt instead of Mini Display Port, could be the same as in issue #2.
(EDIT: since my cable is Mini Display Port, the problem should not be with the 2011 Thunderbolt port)

As Florian Echtler stated himself in issue #2

Hm, I think the only way to solve this would be to run SmcDumpKey on macOS, once with TDM active and once with TDM off, and compare the results... or alternatively, use the dtrace script on the dpd process. However, keep in mind that I tested this with Yosemite on a 2011 iMac, so things may have changed considerably since then...

(In the main page Florian says his machine is 2010 - not 2011)

Unfortunately I don't have MacOS installed anymore so I can't do the comparison Florian suggests - but if someone has it - please share your findings with us.

But, since the tdm_on works - the script is still "good enough" - a working solution!
In my following comment I will give a hint how to use it...

Yours sincerely,
Sami Saarinen
Seinäjoki
Suomi - Finland

@Lumipyry
Copy link

If you have the same problem as I - tdm_on.sh works but tdm_off.sh does not - You can still use this script by not applying rc.local
Then the machine boots in it's Linux OS and you can use the powerbutton to switch to TDM (Target Display Mode).
By long pressing the powerbutton the machine shuts down...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants