Posted on 10-13-2021 02:33 AM
Dear All,
Need help on executing a bash script: How to run this via bash script?
sudo defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Sound -int 18
sudo defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Screen\Mirroring -int 18
sudo defaults write ~/Library/Preferences/ByHost/com.apple.controlcenter.plist Bluetooth -int 18
Thanks!
Raj.
Solved! Go to Solution.
Posted on 10-13-2021 09:14 PM
This one working :
#!/bin/bash
_user=`who | grep console | awk '{ print $1 }'`
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Sound -int 18
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Screen\Mirroring -int 18
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Bluetooth -int 18
exit 0
Posted on 10-13-2021 05:18 AM
This should do it.
#!/bin/sh
CURRENT_USER="$(stat -f%Su /dev/console)"
plistFile="/Library/Preferences/ByHost/com.apple.controlcenter.plist"
defaults write /Users/$CURRENT_USER/$plistFile Sound -int 18
defaults write /Users/$CURRENT_USER/$plistFile "Screen Mirroring" -int 18
defaults write /Users/$CURRENT_USER/$plistFile Bluetooth -int 18
Posted on 10-13-2021 04:37 PM
Hi Bro,
Thanks for the sharing. I tried; however, it is not working.
Thoughts?
Posted on 10-13-2021 09:14 PM
This one working :
#!/bin/bash
_user=`who | grep console | awk '{ print $1 }'`
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Sound -int 18
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Screen\Mirroring -int 18
sudo -u $_user defaults write /Users/$_user/Library/Preferences/ByHost/com.apple.controlcenter.plist Bluetooth -int 18
exit 0