top of page
toduntimesarma

Script To Generate The Plist For Mac: Best Practices And Examples



I need to create a .plist file during post install and the only option I can use is a bash script. I have to create a foo.plist into /Library/launchAgents with a bash script and I've used the following command:




Script To Generate The Plist For Mac



There are two relevant commands here: defaults and /usr/libexec/PlistBuddy. defaults is really set up for managing preference settings, while PlistBuddy is a more general plist tool. For instance, to check and set your dock orientation (which side of the screen it appears on), you could use:


PlistBuddy can easily drill down into arrays and dictionaries within the plist file; for example, to get the URL for the first permanent entry in the right side of your dock, you'd just refer to :persistent-others:0:tile-data:file-data:_CFURLString. (Note that arrays are 0-indexed, so :persistent-others:0 is the first element, :persistent-others:1 is the second, etc). Something like this:


In JAMF, I have the following script scoped out to all newly enroll laptops to run on enrollment. It is a script that creates a Launch Agent and an Application Support/SF folder. In thes script under application support/SF, it will check that the logged in user is not mbsetupuser, finder process is running, and a "done-file" is NOT created so it can run. After creating the script and running it through its process, I do get the popup asking about which role the user is, but after their input, it does not continue with jamf recon -department "$roleID". If I run that same exact script locally on a saved text edit, the script works perfectly, updating the $roleID to JAMF's department field. The problem I see is that if the script is created via a script, it doesn't work as intended, as its not able to do a recon to Jamf, even though I hardcode the path. Please help!


As far as I'm aware, any file filtering/blocking is usually done at the server side, not at the client side, so you'll need to check with the mail server admin to see if your script gets blocked (or just try sending it and see what happens).


If the data is the same you'd be better off just storing a copy of the .plist within your script bundle and just copying it into place. That's easier than creating a new .plist from scratch (and, in all honesty, I'd take the same approach, namely storing the raw data in the script and writing it to a blank file).


set f to (path to desktop)'s POSIX path & "Department-info.plist"set dict to :"1014"tell application "System Events" tell (make new property list file with properties name:f) set value to dict end tellend tell


set f to (path to desktop)'s POSIX path & "Department-info.plist"tell application "System Events" tell (make new property list file with properties name:f) make new property list item at end with properties kind:string, name:"Department", value:"1014" end tellend tell


Forgive me if there is a better way todo this, but I have an app that is generated without a plist, this is partly due to the build system that is cross platform. Is there a way to generate a plist from the command line? I looked at defaults but I can't seem to generate one. I need to be able to set one key CFBundleExecutable.


Preference files are stored in the app container, which isn't the same thing as the app bundle. The app container is created the first time an app is run. The app container is located in the user's /Library/Containers folder. For example, the app container for Outlook is named com.microsoft.Outlook. Within the app container, the .plist file is located in the Data/Library/Preferences folder. For example, the .plist file for Outlook is named com.microsoft.Outlook.plist.


You can take an existing .plist file and modify it with your organization's preferences. In some cases, you can actually copy that .plist file to other Mac devices in your organization that have Office installed. But that doesn't work for all .plist files. Therefore, the preferred method is to create a script that incorporates all the defaults commands that you want to use to set preferences. Then deploy that script to your users. Because preferences are user-specific, you need to run the script in the user's context. If several users share the same device and each user has a different account, then the script needs to be run for each user of that device.


The script is meant to be run on a directory; this can be a directory of extracted plist files from an image, a directory on your own system (ie: /Library), or from a mounted image (ie: /Volumes/mounted_image_file/Users//), you get the idea.


The script also has two dependencies, hexdump.py and ccl_bplist.py. These files can be installed or just simply placed in the same directory you are running the macMRU.py script from. (Installation on OS X 10.11 systems are limited thanks to SIP.)


If I run the script manually, it executes as expected. I can load the plist (launchctl load /Library/LaunchAgents/local.sshfs.plist) and launch it (launchctl start /Library/LaunchAgents/local.sshfs), but it does not run the script. In the logs (cat /var/log/system.log grep local.sshfs) I get:


The "no plist was returned" error means that it was unable to parse the .plist file. I see two problems offhand: Lable should be Label, and should be . You can use the command plutil -lint /Library/LaunchAgents/local.sshfs_mounts.plist to check the plist syntax, although it will not detect whether the data in the plist is valid as a launchd item.


Thanks to Gordon helping me troubleshoot I was able to get the plist file properly formatted (I ended up using plistEdit pro because plists are picky about formatting and using a text editor didn't work for me) and determining that there was an issue in the script that I was attempting to have ran at login.


There were two things that were jamming me up. The first is that launchd was not letting my script spawn sub-process needed to mount an sshfs directory. This was fixed by adding the following key value pair:


If you want to use launchd you'll want to check out other questions here on Super User as well: (eg. How do I run a launchd command as root?) as to where you want to save your configuration file (the plist file) as when it runs depends on what directory it is stored in and how it's loaded (eg. whether you used sudo or not) - similar to cron.


It's also worth noting that launchd tasks if they were scheduled for when the computer is asleep or off, they will run when the computer becomes available again (turning it on or waking it up) - though only once no matter how many days it may have been. Edit: I just was at an Apple document that said that if the machine is off, then you will lose any launch events during that time, (your script will not launch on startup), (sleep does launch script on waking up)


LaunchControl is another GUI for launchd/launchctl. While the alternatives mentioned by others are perfectly capable of launching a script on a daily basis, with LaunchControl you can configure complex schedules (like "once every weekday, on weekends every hour between 2PM and 8PM"). Also it is (AFAIK) the only tool which actually validates the job. If a job does not work as expected it will show you why.


It depends on what you want: iCal scripts will only be executed if you are logged in, cron executes the script without being logged in. I don't know if iCal executes a script if the Mac was turned of at the time the script should have been executed. cron is doing this.


If a calendar event meets your needs, the built-in Automator application also lets you create Calendar Alarms that are triggered by calendar events. You might use some of the built-in UI-based actions to do what you want, or you can also have it run some application or custom AppleScript, JavaScript, or shell script.


By default, Workspace ONE syncs managed distribution licenses for custom apps and volume-licensed public apps daily. The sync is scheduled automatically, allowing Workspace ONE to reconcile newly purchased licenses and updated metadata (descriptions and images). When you upload a location token, you can speed up this process by manually initiating a license sync.


Sometimes an installer package parsed by the VMware Workspace ONE Admin Assistant generates a PLIST file where the application name is incorrect. It is also possible that organizations refer to software by a common or colloquial name that is easily recognized by end users. In either case, administrators can change the name displayed in the Intelligent Hub application catalog before uploading the PLIST to Workspace ONE UEM.


Sometimes an installer package parsed by the VMware Workspace ONE Admin Assistant generates a PLIST file where the version shows Please Edit Me. This problem must be fixed before uploading the PLIST to Workspace ONE UEM.


In some instances, an application successfully installs but the Intelligent Hub continually reports the app as "Installing". If you look in the ManagedSoftwareUpdate.log file (see Gathering Logs), you'll see the app is constantly marked for installation each time the Hub checks for installed software. This is typically the result of a metadata PLIST that doesn't contain the correct receipt or installs arrays. In this instance, you must make one of the following changes to the metadata PLIST generated by Workspace ONE Admin Assistant:


There is a simpler way to make scripts openable in the Finder, which is to give them the .command extension (.tool also works, I think). This automatically makes them open in a terminal window, which is both more and less convenient, depending on whether or not the script fails. :)


Use Automator to turn a shell script into an app. That way, the app can also act as a droplet: drag files onto it and the files will appear to the script as arguments, and are accessible via $1, $2, $3 (or loop through them with for f in "$@").


This works wonderfully for me on OS X Yosemite. I copied it to a script, put it into /usr/local/bin (where other stuff is, in my path) and ran it against a script I run for a Wine application. It created a directory that emulates a normal OS X app, so afterwards you can drag it to wherever you want. I put it into my /Applications folder and now I can run my Wine app like every other application. 2ff7e9595c


1 view0 comments

Recent Posts

See All

댓글


bottom of page