Category filter
Script to hide the VPN icon from the menu bar on Mac
The menu bar on macOS devices makes it easy to access system settings and network settings like VPN, Wi-Fi, battery options, and much more. VPN is required in a corporate setting. IT admins, deploy the necessary VPN configurations to the devices that help them establish the VPN connection, or may perform customizations to include the VPN icon in the menu bar. Adding a VPN icon in the menu bar allows users to connect/disconnect from the VPN easily or keep track of the duration for which the VPN is active. However, if you want to hide the VPN icon to declutter or customize the menu bar of a Mac to include other comparable items, the script described in this doc will help. You can execute the script using the Hexnode’s Execute Custom Script feature.
Scripting Language – Bash
File extension – .sh
Remove the VPN icon from the menu bar
The following script will remove the VPN icon from the menu bar on the currently logged-in user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/sh currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' ) runAsUser() { currentUserID=$(id -u "$currentUser") if [ "$currentUser" != "loginwindow" ]; then /bin/launchctl asuser "$currentUserID" sudo -u "$currentUser" "$@" fi } runAsUser /usr/libexec/PlistBuddy -c 'delete menuExtras: "/System/Library/CoreServices/Menu Extras/VPN.menu"' /Users/$currentUser/Library/Preferences/com.apple.systemuiserver.plist runAsUser /usr/bin/killall cfprefsd runAsUser /usr/bin/killall SystemUIServer exit 0 |
currentUser variable identifies and executes the script to the currently logged-in user.
runAsUser() function executes commands that alter system settings and user preferences specifically for the identified user account. It also modifies user preferences with PlistBuddy, and restarts the system UI directly to the user without any issues.
PlistBuddy is a built-in command that helps users to edit .plist files. runAsUser uses PlistBuddy to remove the entry for the VPN icon from the system UI server file com.apple.systemuiserver.plist. This action will hide the VPN icon from the menu bar.
To apply and recognize the changes, the script restarts the user preferences and the SystemUIServer, which is responsible for the system UI interface.