5

I'd like to be able to toggle between 'Touch bar shows F1, F2, etc keys' and 'Touch bar shows expanded control strip' using defaults.write

I've tried the following:

  1. I saved 'defaults read' to a file, changed the touch bar setting, then saved 'defaults read' to another file, then compared the two files to see the differences.
  2. The only difference seems to be that com.apple.touchbar.agent PresentationModeGlobal switches between fullControlStrip and functionKeys

However, when I apply that change successfully using defaults write com.apple.touchbar.agent PresentationModeGlobal functionKeys, it doesn't change my touch bar.

Is there a reason defaults write isn't having the desired effect?

Ali Torbati
  • 378
  • 1
  • 4
  • 11
Vigoxin
  • 63
  • 7

2 Answers2

5

You've gotten it correct. All that's left to do is to restart the touch bar.

pkill "Touch Bar agent"; killall "ControlStrip";
0

Inspired on @KitchenTable99 I created the following solution.

touch "$HOME/Desktop/Toggle TouchBar Presentation Mode.command"

Create an executable command in the Desktop (or wherever you prefer). Then add this content to it:

function toggleTouchBarPresentationMode() {
   presentationMode="$(defaults read com.apple.touchbar.agent 'PresentationModeGlobal')"

   if [[ "appWithControlStrip" == $presentationMode ]]; then
       targetMode=fullControlStrip
   else
       targetMode=appWithControlStrip
   fi

   defaults write com.apple.touchbar.agent PresentationModeGlobal $targetMode; 
   # restart the control strip
   killall "ControlStrip";
}

toggleTouchBarPresentationMode

You can replace the desired behaviour by replacing the modes you want to toggle.

Josep Alsina
  • 2,762
  • 1
  • 16
  • 12