Posted on 01-17-2022 08:27 PM
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
Solved! Go to Solution.
01-18-2022 09:31 AM - edited 01-18-2022 09:38 AM
@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....
Posted on 01-18-2022 02:29 AM
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?
ES
01-18-2022 09:31 AM - edited 01-18-2022 09:38 AM
@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....
01-18-2022 09:40 AM - edited 01-18-2022 09:40 AM
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!
Posted on 01-19-2022 01:35 PM
@scottb Apologies, Scott, this is a bug and we are working to resolve it as quickly as possible. 😀
Posted on 01-19-2022 02:04 PM
Thank you, @CalleyO - I meant to file it and forgot! Appreciate the heads-up.
02-16-2023 10:18 AM - edited 02-16-2023 01:21 PM
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 ...
Posted on 01-30-2024 04:10 AM
Sorry, I didn't understand that "smiley" edit.
I get the same error as @TomDay
Posted on 01-30-2024 08:40 AM
@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"
Posted on 01-19-2022 04:34 AM
Oh Thankyou! that worked a treat.