Posted on 10-08-2015 08:39 AM
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.
Posted on 10-08-2015 08:55 AM
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
Posted on 10-08-2015 09:01 AM
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.
Posted on 10-08-2015 09:17 AM
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.
Posted on 10-08-2015 09:28 AM
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"
Posted on 10-08-2015 09:37 AM
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.
Posted on 10-08-2015 10:06 AM
@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.
Posted on 10-08-2015 10:09 AM
Example MenuExtra config profile:
https://github.com/nmcspadden/Profiles/blob/master/MenuExtra.mobileconfig
Posted on 10-08-2015 10:42 AM
@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.
Posted on 10-08-2015 10:48 AM
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.
Posted on 10-08-2015 11:46 AM
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.