Enable Screen Mirroring show in menubar

elliots
New Contributor II

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

6 REPLIES 6

elliots
New Contributor II

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
Community Manager
Community Manager

@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.

elliots
New Contributor II

Oh Thankyou! that worked a treat.