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.
Script to show Screen Mirroring on the menu bar
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write com.apple.airplay showInMenuBarIfPresent -int 1 |
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.
Script to hide Screen Mirroring on the menu bar
1 2 3 4 |
#!/bin/bash CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }') CurrentUserUID=$(id -u "$CurrentUser") launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults write com.apple.airplay showInMenuBarIfPresent -int 0 |
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.