Chapter 4. Removing

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

Figure 4.1. Remove Power

Remove Power

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 This tool is available at /Library/Application Support/Power Manager/Remove Power

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

# Part of DssW Power Manager
# Copyright (c) 2018 Dragon Systems Software Limited
# Support:
# 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

echo "Removing DssW Power Manager 4..."
echo ""

cd /

PM_PATH='/Library/Application Support/Power Manager'

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 Unload the Power Manager launchd job

# Unload the Power Manager launchd job
echo "...stopping Power Manager"
/bin/launchctl unload "/Library/LaunchDaemons/"

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 Remove security policy rights

# Remove security policy rights
if [ -e "$PMD_PATH" ]; then
    echo "...revoking security policy rights"
    "$PMD_PATH" -m remove

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 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"

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 Remove our files

# Remove our 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/' # Launchd job ticket (Mac OS X 10.4+)
    '/Library/LaunchAgents/' # Launchd job ticket (Mac OS X 10.5+)
    '/Library/LaunchAgents/' # Launchd job ticket (Mac OS X 10.5+)
    '/Library/LaunchAgents/' # Launchd job ticket (Mac OS X 10.5+)
    '/Applications/Power' # Application
    '/etc/pam.d/' # PAM policy
    '/var/tmp/' # Unix socket directory
    # ...Automator actions and definitions
for (( i = 0 ; i < ${#REMOVE_FILES[@]} ; i++ ))
    if [ -e "$FILEPATH" ]; then
        echo "...removing file: ${FILEPATH}"
        rm -r "${FILEPATH}"

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 Kill still running processes

# Kill still running processes
echo "...stopping user assistants"
    '' # Unix daemon; 4.6.6+
    '' # 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++ ))
    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

Remove Runtime Created Files

The script removes files created at runtime. These files include global preferences and installer receipts.

[Note] 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

Figure 4.8. Remove Power 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 '*' -type f -delete
find '/var/root/Library/Preferences' -name '*' -type f -delete

Say Goodbye

Finally the script says goodbye and asks that the Mac be restarted.

Figure 4.9. Remove Power 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 ***"