Anyone have experience with PlistBuddy?

itupshot
Contributor II

I need to create a simple shell script to call on PlistBuddy to add the new string "/System/Library/CoreServices/Menu Extras/Script Menu.menu" to the existing menuExtras array in the file from the screenshot.

The syntax of the PlistBuddy command is killing me. I just can't find the right combination from the examples I've found. This is a copy of the real plist file to test first.

The purpose is to enable the Script Menu in the menubar when one of my users installs a new AppleScript from Self Service.

860f908a23bf4672a6a05e56b2ac0830

10 REPLIES 10

gregneagle
Valued Contributor

PlistBuddy is unlikely to be the right tool, if your goal is to affect existing user preferences.

You should be looking at configuration profiles instead, as they are designed to do exactly what you are trying to do, and can manage menu items.

-Greg

mm2270
Legendary Contributor III

Yep, Configuration Profiles. That's what you want. Don't manipulate the plist directly with PlistBuddy. I'm not saying it can't come in handy sometimes, but this is not a case where its needed.

itupshot
Contributor II

I've never used configuration profiles, so I don't know which "Option" to choose for this particular case. "Custom Settings" perhaps?

That's why I was thinking of just having a shell script in JSS that could run when the installation policy is triggered in SS.

mm2270
Legendary Contributor III

The issue with PlistBuddy is that its not preferences caching aware. Any changes made to plists with it won't immediately register with the OS unless you do something like restart cfprefsd.
I have to go back and check to see if an existing payload in a Config Profile allows for it, but I know we do it that way (with profiles) It may be a custom option, in which case I would look at something like mcxToProfile.

Incidentally, PlistBuddy isn't even necessary for this if you insist on scripting it.

defaults write ~/Library/Preferences/com.apple.systemuiserver.plist menuExtras -array-add "/System/Library/CoreServices/Menu Extras/Script Menu.menu"

bpavlov
Honored Contributor

I suspect the user may be creating a plist to then upload to Casper as a custom config profile. If that is the case then plistbuddy should work fine along with defaults.

However, you should be able to edit the plist in a text editor such as a TextWrangler for the same purpose if you know what the keys and values are that it should have.

On last bit: don't use the plist you are editing. Instead use, "com.apple.mcxMenuExtras.plist"

You can create a plist called "com.apple.mcxMenuExtras.plist"
and then the entries internally would look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>TimeMachine.menu</key>
    <false/>
    <key>VPN.menu</key>
    <true/>
</dict>
</plist>

Others can share what other menus you can add.

itupshot
Contributor II

@mm2270 Normally, this menu is activated via Script Editor app's Preferences dialog. I'm trying to avoid having to tell users to launch this app to make the menu visible in the menubar.

I tried "defaults write" command, but you're right, it doesn't show up unless you log out and log back in.

Maybe Configuration Profiles can help, but I have never used them so I don't know how to trigger this after running the policy that will install the script from SS.

When I try a manual run of the PlistBuddy command to add the string I get an "Unrecognized Type" error message in the terminal.

However, if I run the "/usr/libexec/PlistBuddy -c Print:menuExtras ~/Desktop/_Casper/_PLIST_FILES/com.apple.systemuiserver.plist" command on that file, it shows me the two existing strings. So, I'm doing something wrong with the syntax of the "Add" command.

gregneagle
Valued Contributor

Example MenuExtra config profile:

https://github.com/nmcspadden/Profiles/blob/master/MenuExtra.mobileconfig

itupshot
Contributor II

@bpavlov I've been using TextWrangler to inspect existing plists. That's how I know what string is inserted into com.apple.systemuiserver.plist by Script Editor when you tell it to enable the Script Menu:
<string>/System/Library/CoreServices/Menu Extras/Script Menu.menu</string>

I'll try both your suggestion, and @gregneagle's sample MenuExtra config profile. I would like that Script Menu to pop up automatically when my users install one of our AppleScripts from Self Service.

mm2270
Legendary Contributor III

You can tie the install of the Config Profile with the Self Service policy installing the Applescript. You might have to package up the Config Profile into a pkg installer and add a postinstall script to install it from whatever location you drop it to, like /private/tmp/ for example, using the profiles command. Add that package to the same Self Service policy that installs the Applescript.
The only downside to this approach would be it won't be manageable via MDM. Only items that get deployed over APNs are manageable afterwards that way. But it will work.

bpavlov
Honored Contributor

You can upload a profile through Casper without having to package or script anything. Instead of selecting NEW just click UPLOAD in the Configuration Profile section.