How to Distribute Power Manager Settings

Let's create a tiny Installer package containing Power Manager's settings. With this package you will have an easy way to distribute schedules, licences, and events across your computers.

Create Your Settings

The first step is to install and set up Power Manager on a single computer. On this computer, create your schedule, apply your licence, and change any other settings you want to apply to your other computers. In the next step we will copy these settings.

Prepare the Package Files

Next we prepare the files to package. The following Terminal.app commands create a folder on the Desktop and then copy Power Manager's preferences into the folder:

mkdir -p ~/Desktop/pmsettings/root
cp /Library/Preferences/uk.co.dssw.powermanager.pmd.plist ~/Desktop/pmsettings/root/.

Power Manager's Scheduler must not be running when the preferences file is altered. Thus our package needs to stop the Scheduler, and then write the preferences file.

We can ensure the Scheduler is not running by unloading its launchd job before installing. Thus a preinstall script is needed:

mkdir ~/Desktop/pmsettings/scripts
printf "%s\\n" '#!/bin/sh' 'sudo launchctl unload /Library/LaunchDaemons/uk.co.dssw.powermanager.pmd.plist' >~/Desktop/pmsettings/scripts/preinstall
chmod +x ~/Desktop/pmsettings/scripts/preinstall

These commands create a scripts folder and a shell script. The preinstall script contains a command to unload Power Manager's Scheduler.

Contents of preinstall:

#!/bin/sh
sudo launchctl unload /Library/LaunchDaemons/uk.co.dssw.powermanager.pmd.plist

Create the Installer Package

The final step is to use macOS's pkgbuild tool to create the Installer package:

/usr/bin/pkgbuild --identifier com.example.powermanager.settings --install-location /Library/Preferences --root ~/Desktop/pmsettings/root --scripts ~/Desktop/pmsettings/scripts --version 1.0.0 ~/Desktop/pmsettings.pkg

After running this commmand, a new pmsettings.pkg file will appear on your Desktop. This package is complete and ready to use.

You can run this package to update Power Manager's settings and after restarting the new settings will take affect.

Use this package to distribute Power Manager's settings across your network.

Troubleshooting and Improvements

Altering preference files on macOS is complicated by macOS's use of a caching mechanism. Changes made directly to preference files may be ignored or overwritten by macOS. Thus this recipe relies on a restart.

Be sure to increment the version between packages with the same identifier. macOS's Installer.app uses the value passed to --version to determine upgrade/downgrade behaviour.

You should consider digitally signing your package. Do this with the /usr/bin/productsign tool.

For more sophisticated configuration, and to avoid the restart, see Power Manager's File Configuration approach.

This article was posted in , , and and tagged .

Published by Graham Miln on