launchd - remove enabled/disabled override in Yosemite

On OS X Yosemite (10.10), is there any way to remove the enabled/disabled override setting for a launchd service?


For example, to permanently disable non-existent service 'test' for root, do this:


sudo launchctl disable user/0/test


Check that it has been added to the disabled list:


sudo launchctl print-disabled user/0


Result:


disabled services = {
    "test" => true
}
login item associations = {
}


Now, how can I delete "test" from the disabled services list?


(I know I can enable it, but I just want to remove the entry entirely.)


Note:


If I reboot my computer, I see that the 'test' override has been added to a launchd disabled file:


sudo cat /var/db/com.apple.xpc.launchd/disabled.0.plist


Result:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>test</key>
    <true/>
</dict>
</plist>


I have tried running this command to manually delete it from the .plist file:


sudo /usr/libexec/Plistbuddy /var/db/com.apple.xpc.launchd/disabled.0.plist -c Delete:test


This does delete it from the file, but it just comes back again when I reboot my computer. Any ideas?

In case launchd keeps the file open and rewrites its content from some cache during shutdown you could try:


$ mv /var/db/com.apple.xpc.launchd/disabled.0.plist /var/db/com.apple.xpc.launchd/disabled.0.plist,backup
$ reboot
...
$ rm /var/db/com.apple.xpc.launchd/disabled.0.plist,backup


(I have not tried this)



If that doesn't work then rebooting into recovery mode and launching the Terminal from menu gives you direct/ unrestricted access to the file while launchd is not running from your system partition. Editing the file in this situation definitely makes any changes stick.


(I tried this and it worked for me)

@tokai, did you have to do anything special when in Recovery Mode to access the /var/db/com.apple.xpc.launchd/disabled.*.plist files? In High Sierra, the directory /var/db appears to be mounted over in Recovery Mode and so the plist files don't appear to be available to edit.


I also tried the rename-and-reboot trick, but that didn't work for me.

I found a way to do it, by entering Single User Mode, following some instructions from https://uit.stanford.edu/service/helpdesk/kernelpanic. The steps were:


  1. Shut down your computer.
  2. On startup, enter single-user mode (Command + S).
  3. From the command line, type
    /sbin/mount -uw /
  4. Edit
    /var/db/com.apple.xpc.launchd/disabled.*.plist
    , as desired.
  5. Type
    exit
launchd - remove enabled/disabled override in Yosemite
 
 
Q