Bash Script

Raj_Jenkin
New Contributor III

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.

 

 

1 ACCEPTED SOLUTION

Raj_Jenkin
New Contributor III

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

View solution in original post

3 REPLIES 3

DBrowning
Valued Contributor

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

 

Raj_Jenkin
New Contributor III

Hi Bro,

Thanks for the sharing. I tried; however, it is not working. 

Thoughts?

Raj_Jenkin
New Contributor III

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

View solution in original post