Enable Screen Mirroring show in menubar

elliots
New Contributor III

Hi,

Our fleet has just jumped from Catalina to Monterey and our users are struggling to locate the screen mirroring "Show in menu Bar" tickbox. 

 

Ideally I would just like a script to enable this or our users. 

I have tried

defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist ScreenMirroring -int 18

but it doesn't seem to work.

weirdly sound and bluetooth work though which are controlled inside the same plist. 

e.g: defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Sound -int 18

anyone got any ideas how the ScreenMirroring preference can be set via terminal script?

 

Cheers,

 

ES

1 ACCEPTED SOLUTION

scottb
Honored Contributor

@elliots :

I found this in the MacAdmins slack...credit to @nstrauss - noting it's "per user":

#!/bin/zsh

logged_in_user=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name 😕 && ! /loginwindow/ { print $3 }')
user_home=$(dscl . -read /users/$logged_in_user NFSHomeDirectory | cut -d " " -f 2)

sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/ByHost/com.apple.controlcenter.plist ScreenMirroring -int 18
sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/com.apple.airplay.plist showInMenuBarIfPresent -bool true

sudo killall "ControlCenter"

Works here in macOS 12.2 beta I'm running, so give it a shot.... 

 

 

 

View solution in original post

9 REPLIES 9

elliots
New Contributor III

Update: 

I have managed to enable the tickbox with:

defaults write com.apple.airplay showInMenuBarIfPresent -bool true

However I have another hurdle. Is it possible to change from the default: "when active" to "always" so it always displays in the menubar?

elliots_0-1642501761217.png

ES

 

scottb
Honored Contributor

@elliots :

I found this in the MacAdmins slack...credit to @nstrauss - noting it's "per user":

#!/bin/zsh

logged_in_user=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name 😕 && ! /loginwindow/ { print $3 }')
user_home=$(dscl . -read /users/$logged_in_user NFSHomeDirectory | cut -d " " -f 2)

sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/ByHost/com.apple.controlcenter.plist ScreenMirroring -int 18
sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/com.apple.airplay.plist showInMenuBarIfPresent -bool true

sudo killall "ControlCenter"

Works here in macOS 12.2 beta I'm running, so give it a shot.... 

 

 

 

scottb
Honored Contributor

Dang it...where the "smiley" is, change to : / (with no space in between)!!!

Someone tell me why pasting into code gives me emojis?  Or rather, how do I stop that!

CalleyO
Contributor III
Contributor III

@scottb  Apologies, Scott, this is a bug and we are working to resolve it as quickly as possible. 😀 

scottb
Honored Contributor

Thank you, @CalleyO - I meant to file it and forgot!  Appreciate the heads-up.

TomDay
Release Candidate Programs Tester

Edit: NM, I didn't see the comment about the inadvertent smiley face! All good now, thx for this!!

 

I'm getting an error when running the script, can you give a look for a scripting novice?

 

 

Script result: awk: syntax error at source line 1
 context is
	/Name � && ! /loginwindow/ >>>  { <<< 
awk: bailing out at source line 1
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
            [command]
usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p
            prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s]
            [<command>]
usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt]
            [-R directory] [-T timeout] [-u user] file ...
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
            [command]
usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p
            prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s]
            [<command>]
usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt]
            [-R directory] [-T timeout] [-u user] file ...

 

 

 

 

Sorry, I didn't understand that "smiley" edit.
I get the same error as @TomDay 

TomDay
Release Candidate Programs Tester

@itibsolution give this a try:

 

#!/bin/zsh

logged_in_user=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name / && ! /loginwindow/ { print $3 }')
user_home=$(dscl . -read /users/$logged_in_user NFSHomeDirectory | cut -d " " -f 2)

sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/ByHost/com.apple.controlcenter.plist ScreenMirroring -int 18
sudo -u "$logged_in_user" /usr/bin/defaults write "$user_home"/Library/Preferences/com.apple.airplay.plist showInMenuBarIfPresent -bool true

sudo killall "ControlCenter"

elliots
New Contributor III

Oh Thankyou! that worked a treat.