This is a legacy guide for Power Manager v3, published 2005 – 2010, and is provided for reference only.
The latest guide is for Power Manager v5.10.6.

Removing Power Manager

Power Manager comes with a shell script that completely removes both installed and runtime created files.

The script is fairly complex as it deals with all combinations of the Power Manager packages and executables.

The removal script is presented in full below. If you just want to remove Power Manager, stop reading and run the Remove Power Manager… command in the System Preference.

For those wanting to learn more about the specifics of removing Power Manager we will walk through the script in detail.

The script is located deep within the System Preference. It is a shell script and requires root privileges.

/Library/PreferencePanes/Power Manager.prefPane/Contents/MacOS/Remove Power Manager.app/Contents/Resources/Remove Power Manager.sh

Set Up and Presentation

The script sets out the copyright details, then presents feedback to the user informing them of the implications of continuing.

Finally we change to a known directory.

#!/bin/sh
# Part of DssW Power Manager
# Copyright (c) 2007 Dragon Systems Software Limited
# Support: support@dssw.co.uk
#
# This script completely removes Power Manager from the host Mac.
# A restart is required on completion to tidy up after removing pmauth
# and rights.
if [[ $EUID -ne 0 ]]; then
  echo "You must be a root to run this script" 2>&1
  exit 1
fi
echo "Removing DssW Power Manager 3..."
echo ""
cd /
##

Stop the Daemon

The daemon responsible for Power Manager is stopped in two stages.

Depending on the managing process either launchd needs to have the Power Manager job removed, or the SystemStarter directory needs to be deleted.

# Disable and stop Power Manager
if [ -e '/usr/local/powermanager/bin/powermanagerctl' ]; then
    echo "...turning off Power Manager's schedule"
    /usr/local/powermanager/bin/powermanagerctl scheduler.setenabled no
fi
echo "...stopping Power Manager"
if [ -e "/Library/LaunchDaemons/uk.co.dssw.powermanager.plist" ]; then 
    # Power Manager 3.5+; launchd managed
    # Ask launchctl to stop the daemon
    /bin/launchctl unload "/Library/LaunchDaemons/uk.co.dssw.powermanager.plist"
fi
echo "...stopping Power Manager Assistants"
if [ -e "/Library/LaunchAgents/uk.co.dssw.pmassistant.plist" ]; then 
    # Ask launchctl to stop user agents
    /bin/launchctl unload "/Library/LaunchAgents/uk.co.dssw.pmassistant.plist"
fi
echo "...stopping Power Manager Assistants"
if [ -e "/Library/LaunchAgents/uk.co.dssw.pmloginwindow.plist" ]; then 
    # Ask launchctl to stop user agents
    /bin/launchctl unload "/Library/LaunchAgents/uk.co.dssw.pmloginwindow.plist"
fi
if [ -e "/Library/StartupItems/PowerManager" ]; then 
    # Power Manager 3.0 - 3.2.1, and 3.5+ under Mac OS X 10.3.9
    # Send a stop command to the daemon via the StartupItem package
    /Library/StartupItems/PowerManager/PowerManager stop
    sleep 2
fi    
##

Revoking the Security Policy

Various elements within Power Manager use the security policy database to delegate authentication and authorization to Mac OS X. On removal we remove Power Manager’s presence from the security policy database.

Each Power Manager tool knows about the security rights it installs; each tool is also responsible for removing its rights.

Mac OS X 10.3.9 asks for an administrator password for each right removed. This behaviour is unfriendly and has caused users to give up part way through the installation process. To avoid this burden, we skip the this step if the Mac is running Mac OS X 10.3.9. This leaves unneeded policies in the database but it is a safe decision.

We recommend removing all uk.co.dssw.powermanager. rights by hand on Mac OS X 10.3.9 to avoid this password burden.

# Programmatically remove the global login item
if [ -e '/usr/local/powermanager/bin/pmassistant.app/Contents/MacOS/pmassistant' ]; then
    echo "...removing assistants"
    /usr/local/powermanager/bin/pmassistant.app/Contents/MacOS/pmassistant -r
fi
# Remove security policy rights
if [ -e '/usr/local/powermanager/bin/powermanagerd' ]; then
    # Skip this step on Mac OS X 10.3.9
    OSVERSION=`sw_vers -productVersion`
    if [ "$OSVERSION" != "10.3.9" ]; then
    	echo "...revoking security policy rights"
    	/usr/local/powermanager/bin/powermanagerd -u
    fi
fi
##

Remove the Login Window Plugin

The login window security plugin needs to remove its security mechanism before uninstalling. The security removal is performed by a command line tool included within the plugin.

# Remove the authentication plug-in
if [ -e "/System/Library/CoreServices/SecurityAgentPlugins/pmauth.bundle" ]; then
    echo "...disable login window notification"
    "/System/Library/CoreServices/SecurityAgentPlugins/pmauth.bundle/Contents/MacOS/pmauthctl" -u
fi
##

If the removal fails or is interrupted, the Mac may be left unable to return to the Login Window. This is because the Login Window plug-in pmauth uses the Power Manager framework. If the framework does not exist - or has been removed - the plug-in will not load and will crash the Login Window.

To ensure this does not occur, the following two commands remove specific pmauth lines from the /etc/authorization file.

This in-place perl command provides a ‘belt and braces’ approach to the problem.

# Ensure authorization contains no mention of pmauth
sed -E -e '/^[[:space:]]+<string>pmauth:test<\/string>$/d' /etc/authorization > /tmp/authorization.dssw
install -b -B .pm -m 0644 -o root -g wheel -S /tmp/authorization.dssw /etc/authorization
rm /tmp/authorization.dssw
##

Remove Supporting Files and Folders

With the daemon stopped and the security rights revoked, the remaining Power Manager files can be removed.

# Remove our files
REMOVE_FILES=(
    '/Library/Application Support/Power Manager' # Preference pane's support files
    '/Library/Automator/PMCancelEvents.action'
    '/Library/Automator/PMDelayEvents.action'
    '/Library/Automator/PMDeleteEvents.action'
    '/Library/Automator/PMEvent.definition'
    '/Library/Automator/PMEventsToStrings.caction'
    '/Library/Automator/PMExportEvents.action'
    '/Library/Automator/PMFilterEvents.action'
    '/Library/Automator/PMImportEvents.action'
    '/Library/Automator/PMListEvents.action'
    '/Library/Automator/PMNewEvent.action'
    '/Library/Automator/PMNextEvent.action'
    '/Library/Automator/PMQuickSchedule.action'
    '/Library/Automator/PMToggleScheduler.action'
    '/Library/Documentation/Help/Power Manager Help' # Help Book symlink
    '/Library/Frameworks/PowerManager.framework' # Shared framework needed to talk to the daemon
    '/Library/LaunchDaemons/uk.co.dssw.powermanager.plist' # Launchd daemon job ticket (Mac OS X 10.4+)
    '/Library/LaunchAgents/uk.co.dssw.pmassistant.plist' # Launchd agent job ticket (Mac OS X 10.5+)
    '/Library/LaunchAgents/uk.co.dssw.pmloginwindow.plist' # Launchd agent job ticket (Mac OS X 10.5+)
    '/Library/PreferencePanes/Power Manager.prefPane' # Preference pane
    '/Library/StartupItems/PowerManager' # StartupItem (Mac OS X 10.3.9)
    '/Library/Widgets/Power Manager.wdgt' # Dashboard widget (Mac OS X 10.4+)
    '/System/Library/CoreServices/SecurityAgentPlugins/pmauth.bundle' # loginwindow plugin
    '/usr/local/powermanager' # Unix daemon and command line tool
    '/var/tmp/uk.co.dssw.powermanager' # Unix socket directory
    );
for (( i = 0 ; i < ${#REMOVE_FILES[@]} ; i++ ))
do
    FILEPATH=${REMOVE_FILES[$i]}
    if [ -e "$FILEPATH" ]; then
    	echo "...removing file: ${FILEPATH}"
    	rm -r "${FILEPATH}"
    fi
done
##

In Power Manager 3.6.1 we forgot to remove a single Automator action. This mistake caused Automator to crash. In order to prevent this mistake ever happening again, we added an additional check to the removal script with regard to Automator actions.

The additional check looks for any Automator actions that mention DssW in their Info.plist files. If we are mentioned, those actions are removed. The command to do this is fairly complex.

# Remove Automator actions with our signature (belt and braces)
echo "...removing Automator actions"
find '/Library/Automator' -path '/Library/Automator/PM*/Contents/Info.plist' -type f -print0 | xargs -0 grep -l 'uk.co.dssw.powermanager.' | sed 's/\/Contents\/Info.plist//g' | xargs -n 1 rm -r
##

The first part finds all the Automator actions matching our file naming convention. The list of files returned points to each action’s Info.plist.

find '/Library/Automator' -path '/Library/Automator/PM*/Contents/Info.plist' -type f -print0

The next part reduces the returned list to files containing uk.co.dssw.powermanager..

xargs -0 grep -l 'uk.co.dssw.powermanager.'

We now have a list of Info.plist files that need to be removed. In fact, we need to move up two directories; this will leave us with a list of Automator actions, and not a list of Info.plist files within those actions.

The next part uses sed to strip the /Contents/Info.plist suffix from the path.

sed 's/\/Contents\/Info.plist//g'

Finally, we have a list of Automator actions that match our file naming convention, and mention our unique company identifier in their Info.plist file.

The final part of the command uses xargs to translate the list into a series of recursive removal commands.

xargs -n 1 sudo rm -r

Clean Up Processes

Next issue killall commands for each of the processes Power Manager uses. By calling killall with sudo permissions all instances of each process will be killed.

# Kill still running processes
echo "...stopping user assistants"
KILL_PROCESSES=(
    'powermanagerd' # Unix daemon
    'Power Manager Menu' # Users' menu status bar
    'pmassistant' # User space assistant
    'pmloginwindow' # Login Window assistant
    'Power Manager Scripting' # AppleScript support application
    'System Preferences' # Preference pane host application
    );
for (( i = 0 ; i < ${#KILL_PROCESSES[@]} ; i++ ))
do
    PROCESS=${KILL_PROCESSES[$i]}
    echo "   ${PROCESS}"
    killall "${PROCESS}" 2>&1
    # Kill any outstanding process with brute force (needed for powermanagerd)
    ps -e -o pid,command | grep "${PROCESS}" | awk '{print$1}' | xargs -n 1 kill -9
done
##

Remove Runtime Created Files

To clean up fully the script must also remove files created at runtime.

The script removes all the installer receipts and shared preferences.

Preferences of individual users are not removed by this script. This was deemed too complex to perform correctly for every situation.

No essential information is stored within individual user’s Power Manager related preferences.

It is always safe to remove user’s individual preferences beginning with uk.co.dssw.powermanager.

# Remove the run time created files
echo "...removing preferences and installer receipts"
find '/Library/Receipts' -name 'Power Manager *.pkg' -type d -print0 | xargs -0 rm -r
find '/Library/Preferences' -name 'uk.co.dssw.powermanager.*' -type f -delete
find '/var/root/Library/Preferences' -name 'uk.co.dssw.powermanager.*' -type f -delete
##

Finally Restart

After altering the security rights the Mac must be restarted. So we nicely ask the user to perform a restart and exit.

# Say goodbye
echo ""
echo "...Finished."
echo ""
# Ask the user to restart to ensure running processes come down fully
echo ""
echo "Thank you. DssW Power Manager has been removed."
echo ""
echo "Please now restart."
echo ""
echo "*** Success ***"