Skip to main content
Question

Menu Bar Icons and Configuration

  • December 5, 2019
  • 1 reply
  • 75 views

Forum|alt.badge.img+11
  • Valued Contributor
  • 135 replies

Hello JAMF Nation,

I am currently trying to configure Volume, VPN, & Battery to not only open but have certain defaults checked off as well.

For VPN wanted to have:
- Show Time Connected
- Show Status While Connected

For Battery:
- Show Percentage

What I have done in the past that used to work:
Have a custom settings payload with a plist that was converted to a mobile.config and then uploaded to JAMF reaching out to com.apple.systemuiserver that plist is the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
    <dict>
        <key>PayloadContent</key>
        <array>
            <dict>
                <key>PayloadContent</key>
                <dict>
                    <key>com.apple.systemuiserver</key>
                    <dict>
                        <key>Set-Once</key>
                        <array>
                            <dict>
                                <key>mcx_preference_settings</key>
                                <dict>
                                    <key>NSStatusItem Visible Siri</key>
                                    <false/>
                                    <key>NSStatusItem Visible com.apple.menuextra.airplay</key>
                                    <true/>
                                    <key>NSStatusItem Visible com.apple.menuextra.volume</key>
                                    <true/>
                                    <key>NSStatusItem Visible com.apple.menuextra.vpn</key>
                                    <true/>
                                    <key>__NSEnableTSMDocumentWindowLevel</key>
                                    <true/>
                                    <key>menuExtras</key>
                                    <array>
                                        <string>/System/Library/CoreServices/Menu Extras/Battery.menu</string>
                                        <string>/System/Library/CoreServices/Menu Extras/AirPort.menu</string>
                                        <string>/System/Library/CoreServices/Menu Extras/Volume.menu</string>
                                        <string>/System/Library/CoreServices/Menu Extras/Displays.menu</string>
                                        <string>/System/Library/CoreServices/Menu Extras/VPN.menu</string>
                                    </array>
                                </dict>
                            </dict>
                        </array>
                    </dict>
                </dict>
                <key>PayloadDisplayName</key>
                <string>Custom: (com.apple.systemuiserver)</string>
                <key>PayloadEnabled</key>
                <true/>
                <key>PayloadIdentifier</key>
                <string>com.apple.mdm.macserver-imac.local.e619bbc0-3444-0136-d464-2c87a33a6849.alacarte.customsettings.04410560-3445-0136-d466-2c87a33a6849</string>
                <key>PayloadType</key>
                <string>com.apple.ManagedClient.preferences</string>
                <key>PayloadUUID</key>
                <string>04410560-3445-0136-d466-2c87a33a6849</string>
                <key>PayloadVersion</key>
                <integer>1</integer>
            </dict>
        </array>
        <key>PayloadDescription</key>
        <string>Add shortcuts to the menu bar</string>
        <key>PayloadDisplayName</key>
        <string>Settings for menubar_icons</string>
        <key>PayloadEnabled</key>
        <true/>
        <key>PayloadIdentifier</key>
        <string>com.apple.mdm.macserver-imac.local.e619bbc0-3444-0136-d464-2c87a33a6849.alacarte</string>
        <key>PayloadOrganization</key>
        <string>CompanyName</string>
        <key>PayloadRemovalDisallowed</key>
        <false/>
        <key>PayloadScope</key>
        <string>System</string>
        <key>PayloadType</key>
        <string>Configuration</string>
        <key>PayloadUUID</key>
        <string>e619bbc0-3444-0136-d464-2c87a33a6849</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
    </dict>
</plist>

This now is no longer working for my Enrollments on Mojave 10.14.6

What I am currently trying to do is create a profile solely dedicated to Menu Bar Items and through a one line command under Files & Processes Execute Command:

user=$(stat -f %Su /dev/console); sudo -u $user open "/System/Library/CoreServices/Menu Extras/vpn.menu" ; sudo -u $user open "/System/Library/CoreServices/Menu Extras/Volume.menu" ; sudo -u $user open "/System/Library/CoreServices/Menu Extras/Battery.menu"

Which opens the services just fine but writing to them possibly via a script has been quite challenging as nothing I have tried does the trick. I tried -booling it prior to opening the services but this did not work at all.

user=$(stat -f %Su /dev/console);  sudo -u $user /usr/bin/defaults write com.apple.menuextra.vpn ShowTimeConnected -bool YES;  sudo -u $user /usr/bin/defaults write com.apple.menuextra.vpn ShowStatusWhileConnecting -bool YES; sudo -u $user open "/System/Library/CoreServices/Menu Extras/vpn.menu" ; sudo -u $user open "/System/Library/CoreServices/Menu Extras/Volume.menu" ; sudo -u $user open "/System/Library/CoreServices/Menu Extras/Battery.menu"

Would anyone have any possible Ideas on how I can achieve this or a much cleaner way of getting it accomplished I would be grateful.

Thanks in Advance.

1 reply

mallej
Forum|alt.badge.img+4
  • Contributor
  • 21 replies
  • April 14, 2022

maybe helpful

#!/bin/sh # This script sets VPN settings for the currentuser. # The presumption is that this script will be executed as root from a launch daemon # or from some management agent. To execute a single command as the current user # you can use the `runAsUser` function below. # original by Armin Briegel - Scripting OS X # https://scriptingosx.com/2020/08/running-a-command-as-another-user/ # modified by Jens Malessa # last 14.04.2022 # variable and function declarations export PATH=/usr/bin:/bin:/usr/sbin:/sbin # get the currently logged in user currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' ) # global check if there is a user logged in if [ -z "$currentUser" -o "$currentUser" = "loginwindow" ]; then echo "no user logged in, cannot proceed" exit 1 fi # now we know a user is logged in # get the current user's UID uid=$(id -u "$currentUser") # convenience function to run a command as the current user # usage: # runAsUser command arguments... runAsUser() { if [ "$currentUser" != "loginwindow" ]; then launchctl asuser "$uid" sudo -u "$currentUser" "$@" else echo "no user logged in" # uncomment the exit command # to make the function exit with an error when no user is logged in # exit 1 fi } # main code starts here # Enable "Show Time Connected" and "Show Status While Connecting" in VPN status bar for currentuser runAsUser defaults write com.apple.networkConnect VPNShowTime -bool TRUE runAsUser defaults write com.apple.networkConnect VPNShowStatus -bool TRUE