Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
Last active October 28, 2020 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talkingmoose/1018cccbff04ac95d85939e748a11ef5 to your computer and use it in GitHub Desktop.
Save talkingmoose/1018cccbff04ac95d85939e748a11ef5 to your computer and use it in GitHub Desktop.
Quits the Wi-Fi menu item for the current user. Effectively unchecks the "Show Wi-Fi status in menu bar" item in System Preferences > Network.
#!/bin/zsh
# get current logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser"
# get current user home folder path
homeFolder=$( /usr/bin/dscl . read /Users/talkingmoose NFSHomeDirectory | /usr/bin/awk -F ": " '{ print $2 }' )
echo "Current user home folder is $homeFolder"
# get a list of running menu items
menuItemsList=$( /usr/libexec/PlistBuddy -c "Print :menuExtras:" ~/Library/Preferences/com.apple.systemuiserver.plist | /usr/bin/grep /System )
echo "$menuItemsList"
# get the line number of the Airport.menu item from the menu items list
lineNumber=$( /usr/bin/awk '/AirPort.menu/{ print NR }' <<< "$menuItemsList" )
echo "Airport.menu is on line $lineNumber"
# get index of the line number (indices begin zero, subtract 1)
menuItemIndex=$(( lineNumber - 1 ))
echo "Therefore, the index of Airport.menu is $menuItemIndex"
# set visibility of Airport.menu to false
/usr/bin/defaults write "$homeFolder/Library/Preferences/com.apple.systemuiserver.plist" "NSStatusItem Visible com.apple.menuextra.airport" -bool false
# remove the Airport.menu item from the plist
/usr/libexec/PlistBuddy -c "Delete :menuExtras:$menuItemIndex" "$homeFolder/Library/Preferences/com.apple.systemuiserver.plist"
# restart cfprefsd and the UI server
kill cfprefsd
/usr/bin/killall SystemUIServer
exit 0
#!/bin/zsh
# get current logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser"
# get current user home folder path
homeFolder=$( /usr/bin/dscl . read /Users/talkingmoose NFSHomeDirectory | /usr/bin/awk -F ": " '{ print $2 }' )
echo "Current user home folder is $homeFolder"
# get a list of running menu items
menuItemsList=$( /usr/libexec/PlistBuddy -c "Print :menuExtras:" ~/Library/Preferences/com.apple.systemuiserver.plist | /usr/bin/grep /System )
echo "$menuItemsList"
# get the line number of the Airport.menu item from the menu items list
lineNumber=$( /usr/bin/awk '/AirPort.menu/{ print NR }' <<< "$menuItemsList" )
echo "Airport.menu is on line $lineNumber"
# get index of the line number (indices begin zero, subtract 1)
menuItemIndex=$(( lineNumber - 1 ))
echo "Therefore, the index of Airport.menu is $menuItemIndex"
# set visibility of Airport.menu to false
/usr/bin/defaults write "$homeFolder/Library/Preferences/com.apple.systemuiserver.plist" "NSStatusItem Visible com.apple.menuextra.airport" -bool false
# remove the Airport.menu item from the plist
/usr/libexec/PlistBuddy -c "Delete :menuExtras:$menuItemIndex" "$homeFolder/Library/Preferences/com.apple.systemuiserver.plist"
# restart cfprefsd and the UI server
kill cfprefsd
/usr/bin/killall SystemUIServer
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment