Category filter

Script to show/hide Screen Mirroring icon on the menu bar on Mac

Screen mirroring on a Mac involves using AirPlay, a proprietary wireless streaming protocol developed by Apple. This feature allows you to display the contents of your Mac’s screen on compatible AirPlay-enabled devices, such as Apple TV and certain smart TVs, provided they are connected to the same Wi-Fi network as your Mac. By accessing the Screen Mirroring option in the menu bar, users can easily use this feature during meetings or presentations and adjust display settings directly. The provided scripts help IT administrators to manage the visibility of the Screen Mirroring option on the menu bar for managed devices through Hexnode’s “Execute Custom Script” action.

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Script to show Screen Mirroring on the menu bar

The script retrieves the currently logged-in macOS user and their user ID, then writes the value 1 to ‘showInMenuBarIfPresent’ to display the Screen Mirroring option on the menu bar.

With the execution of this script, the Screen Mirroring option will be displayed on the menu bar of the Mac, and the option Always Show in Menu Bar will be enabled in System Settings > Control Centre > Screen Mirroring.

The Screen Mirroring icon will appear in the menu bar on Mac once the script to show or hide it is executed

Script to hide Screen Mirroring on the menu bar

The script writes the value 0 to ‘showInMenuBarIfPresent’ to hide the Screen Mirroring option on the menu bar.

By executing this script, the Screen Mirroring option will be hidden from the menu bar on the Mac, and the Always Show in Menu Bar option will be disabled in System Settings > Control Center > Screen Mirroring.

Notes:

  • For macOS version 12.0 and below, the Show in Menu Bar option can be enabled or disabled from System Preferences > Dock & Menu Bar > AirPlay.
  • Even though the script can adjust the visibility of Screen Mirroring in the Mac menu bar, users retain the ability to manually change this option from the device end.
  • 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