Removing
The removal tool deals with all combinations of the Power Manager packages. The tool requires administrator rights to run.
The removal script used by the tool is presented in full below. If you just want to remove Power Manager, stop reading and run Remove Power Manager.app. This tool is available at /Library/Application Support/Power Manager/Remove Power Manager.app
.
Additionally, you can launch the removal tool by holding down the shift key and clicking on Power Manager’s status menu bar. Then select the menu item: Remove Power Manager….
The Removal Script in Detail
For those wanting to learn more about the specifics of removing Power Manager we will walk through the script in detail.
Set Up and Presentation
The script sets out the copyright details, and then checks the effective user identity (EUID
). The script must be run as root user in order to continue.
The script changes to a known location and defines a few constants to common Power Manager folders.
Figure 4.2. Remove Power Manager.sh:1
#!/bin/sh
#
# Part of DssW Power Manager
# Copyright (c) 2018 Dragon Systems Software Limited
# Support: support@dssw.co.uk
#
# This script removes Power Manager 4 from the booted volume.
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 4..."
echo ""
cd /
PM_PATH='/Library/Application Support/Power Manager'
TOOLS_PATH="$PM_PATH/Tools"
PMCTL_PATH="$TOOLS_PATH/pmctl"
PMULI_PATH="$TOOLS_PATH/pmuli"
DAEMONS_PATH="$PM_PATH/Daemons"
PMD_PATH="$DAEMONS_PATH/pmd"
Stop the Daemon
Power Manager’s daemon needs to be stopped before removal. First a command to disable the scheduler is issued to dequeue any pending IOPMQueue requests. Then launchd is asked to unload the daemon’s job ticket.
Figure 4.3. Remove Power Manager.sh:26: Unload the Power Manager launchd job
# Unload the Power Manager launchd job
echo "...stopping Power Manager"
/bin/launchctl unload "/Library/LaunchDaemons/uk.co.dssw.pmd.plist"
Revoke Security Rights
Power Manager uses macOS’s security policy database. Local authentication and authorisation issues are delegated to macOS through these policies. On removal we completely remove Power Manager’s presence from the security policy database.
pmrights makes the security policy removal process simple.
Figure 4.4. Remove Power Manager.sh:31: Remove security policy rights
# Remove security policy rights
if [ -e "$PMD_PATH" ]; then
echo "...revoking security policy rights"
"$PMD_PATH" -m remove
fi
Remove Universal Login Items
On macOS 10.4, also known as Tiger, Power Manager used a Universal Login Item. This item is removed using pmuli.
Figure 4.5. Remove Power Manager.sh:38: Remove any universal login items (Mac OS X 10.4)
# Remove any universal login items (Mac OS X 10.4)
if [ -e "$PMULI_PATH" ]; then
echo "...removing universal login items"
"$PMULI_PATH" remove "$PM_PATH"
fi
Remove Supporting Files and Folders
The script iterates over a list of supporting files and folders. Each entry in the list is checked and then removed.
Figure 4.6. Remove Power Manager.sh:45: Remove our files
# Remove our files
REMOVE_FILES=(
'/Library/Application Support/Power Manager' # Shared tools and core engine
'/Library/Frameworks/PowerManager.framework' # Shared framework needed to talk to the daemon
'/Library/LaunchDaemons/uk.co.dssw.pmd.plist' # Launchd job ticket (Mac OS X 10.4+)
'/Library/LaunchAgents/uk.co.dssw.pmnotify.plist' # Launchd job ticket (Mac OS X 10.5+)
'/Library/LaunchAgents/uk.co.dssw.pmnotify.login.plist' # Launchd job ticket (Mac OS X 10.5+)
'/Library/LaunchAgents/uk.co.dssw.pmuser.plist' # Launchd job ticket (Mac OS X 10.5+)
'/Library/LaunchDaemons/uk.co.dssw.powermanager.bridge.plist'
'/Applications/Power Manager.app' # Application
'/etc/pam.d/uk.co.dssw.powermanager' # PAM policy
'/var/tmp/uk.co.dssw.powermanager' # Unix socket directory
# ...Automator actions and definitions
'/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/PMResetEvents.action'
'/Library/Automator/PMToggleScheduler.action'
);
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
Clean Up Processes
Next the script issues killall
commands for each of the processes Power Manager uses. By calling killall
with sudo
permissions all instances of each process will be killed.
Figure 4.7. Remove Power Manager.sh:82: Kill still running processes
# Kill still running processes
echo "...stopping user assistants"
KILL_PROCESSES=(
'uk.co.dssw.powermanager.pmd' # Unix daemon; 4.6.6+
'uk.co.dssw.powermanager.pmuser' # User space assistant; 4.6.6+
'pmd' # Unix daemon
'pmnotify' # Users' menu status bar and notifier
'pmuser' # User space assistant
'Power Manager Notifications' # Users' menu status bar and notifier; 4.4.2+
);
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
The script removes files created at runtime. These files include global preferences and installer receipts.
User 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.
Figure 4.8. Remove Power Manager.sh:103: Remove the run time created files
# 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
Say Goodbye
Finally the script says goodbye and asks that the Mac be restarted.
Figure 4.9. Remove Power Manager.sh:110: Say goodbye
# 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 ***"