Skip to main content
Question

Adding Screen Lock Shortcut to Touchbar

  • August 22, 2019
  • 3 replies
  • 10 views

Forum|alt.badge.img+3

Hey All,

I'm trying to run a command that will allow me to add the screen lock to touchbar.

I've been using the following command.

defaults write com.apple.controlstrip MiniCustomized -array-add com.apple.system.screen-lock
killall ControlStrip

However when the command runs the touch bar refreshes and everyone on my touch bar goes away and the only shortcut is the screen lock

I want to add the screen lock shortcut to the furtherest right position next to the touch ID sensor.

Some info:
Computer is running 10.14.6

Any help would be appreciated.

3 replies

Forum|alt.badge.img+5
  • New Contributor
  • August 23, 2019
#!/bin/bash

# Get the Username of the currently logged user
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
echo $loggedInUser

##Set control strip for user
#full
sudo -u $loggedInUser rm ~/Library/Preferences/com.apple.controlstrip.plist
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.group.brightness
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.mission-control
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.launchpad
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.group.keyboard-brightness
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.group.media
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.group.volume
sudo -u $loggedInUser defaults write com.apple.controlstrip FullCustomized -array-add com.apple.system.screen-lock
#mini
sudo -u $loggedInUser defaults write com.apple.controlstrip MiniCustomized -array-add com.apple.system.mute
sudo -u $loggedInUser defaults write com.apple.controlstrip MiniCustomized -array-add com.apple.system.volume
sudo -u $loggedInUser defaults write com.apple.controlstrip MiniCustomized -array-add com.apple.system.brightness
sudo -u $loggedInUser defaults write com.apple.controlstrip MiniCustomized -array-add com.apple.system.screen-lock
killall ControlStrip

Forum|alt.badge.img+16
  • Valued Contributor
  • August 27, 2019

thanks @TrH This is exactly what I was looking for.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • September 17, 2019

How would I create the plist itself. Is there a command I need to run in terminal.