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

Disclaimer:


The Sample Scripts provided below are adapted from third-party Open-Source sites.

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.

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.

Notes:

  • This script requires macOS 12 and later versions.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository