8

A number of the background services used by the Photos app perform functions I'm not interested in benefitting from (and in some cases, actively do not want). Primarily these are photoanalysisd and cloudphotosd. I'm reasonably certain that the former is not strictly necessary for the Photos app to operate (if needed for some features); I'm slightly less certain about the latter but that isn't precisely the thrust of the question. (photolibraryd I'm aware the app needs in order to run properly at all, and so I'm not touching it).

Where I seem to be stuck is that their launching does not appear to respect launchctl disable. Indeed, launchctl print gui/$UID includes both daemons within the disabled services section, with the flag set to true, while neither are running, and the Photos app will still trigger these to be launched as soon as it is started. It isn't enabling them in launchd, as the flags remain unchanged when I check after testing by launching the Photos app.

Considering the possibility I was disabling them in the wrong launchd domain, I went on to try disabling them in the system domain, to no avail - launching Photos still starts these two services as soon as it starts.

I also attempted to use the legacy launchctl unload -w pattern on the corresponding .plist file in /System/Library/LaunchAgents/, but was informed by launchctl in that case that the service could not be found.

In case some volatile state needed to be flushed or reloading done, I shut down and rebooted the system subsequent to ensuring that those services were flagged as disabled. They still returned as soon as the Photos app was launched.

launchctl blame gui/$UID/cloudphotosd simply stated that the service was launched for xpc (mach), which doesn't really tell me much (the cross-process communication here is probably just the photos app launching the service).

I'm wondering how to really disable these particular background processes, so that they cannot be launched by the Photos app, without out and out deleting them from the system or making other "destructive" changes. Or in other words, while I could probably simply find their actual executables and move them somewhere for archival, not being all that familiar with the functioning of launchd I'm curious as to whether there is a way working within its system to really forbid certain services from being launched. I thought that was launchctl disable... but it seems not, as that does not appear to have any effect in this instance.

EDIT: Should clarify, this is on macOS 10.14/Mojave.

3
  • 1
    Hm, maybe chmod -xing the binaries? I did that when I was maintaining two separate versions of iTunes, to prevent me from launching the new one accidentally.
    – SilverWolf
    Commented Sep 29, 2018 at 13:47
  • It's still working "outside" of launchd/the services system, but that's less destructive still than just moving them to elsewhere. If it turns out there's no way within the system that's probably what I'll do, thanks! Commented Sep 29, 2018 at 15:20
  • You're quite welcome! I'll post it as an answer.
    – SilverWolf
    Commented Sep 29, 2018 at 15:23

3 Answers 3

3

Try running chmod -x on the binaries. This will prevent them from launching at all until you make them executable again.

I don't know how SIP will affect this, since you're modifying built-in programs. You may have to disable it.

1

This turns out to be unpleasant. I'm sorry to say that Apple really screwed this one up (and since it's obsolete, there won't be a permanent fix). The good news is that since it's obsolete, most of the fixes enumerated here and elsewhere are likely to keep working.

  1. First, if your system is insanely laggy because the photoanalysisd is running jobs over and over, doing nothing, you can just:

    sudo killall photoanalysisd
    

This will give you some breathing room so that you can actually access your disk. There, that's better, isn't it? If that's not enough, you can always do a while true do sudo killall photoanalysisd ; sleep 60 ; done

  1. Permanent fixes all involve turning off System Integrity Protection (SIP), because the photo analysis daemon and its configuration are all under the protection of SIP. It's possible that a system update will reset to Apple defaults, but since your system is obsolete now, it's unlikely.

So, reboot into the Recovery console (reboot, hold R as the reboot occurs, and then open Terminal.

    csrutil disable
    shutdown -r now

to turn off SIP, then reboot

Now, all you have to do is to move the configuration file that tells launchd to start photoanalysisd to start.

    cd /System/Library/LaunchAgents/
    mkdir DISABLED
    sudo mv com.apple.photoanalysisd.plist DISABLED
    sync

and then reboot into recovery mode, again by holding R during boot.

    shutdown -r now

hold down r open terminal, and csrutil enable shutdown -r now

And now, photoanalysisd will not come up.

Sadly,

  1. Notice that the plist for photoanalysisd has things like delay, whether or not to repeat, and so on. In my experimentation, none of them are used, because although launchd has these facilities, photoanalysisd appears to have its own idea of restarting to wait for work, and doesn't use the launchd facilities. SIGH. I suspect this is less of a big deal on APFS, but on HFS+, it doesn't have the metadata to do this efficiently, so the "no big deal, tested and working on 'my machine'" photoanalysisd is actually a disk bandwidth and cpu hog, doing nothing whatsoever after the initial classification is done.

I would LOVE to know a way to start photoanalysisd only on demand, but the combination of SIP and no documented job protocol makes that hard without documentation. I even looked in the binary for strings that it might be looking for in commands, launchd properties, etc., but there's no documentation. If I ever upgrade my lovely tank of a 2009 iMac to an SSD, I'll see. That said, the hardware would still be SATA not NVMe, so the huge number of command channels that could make the disk interface so fast that it doesn't care won't be there. If someone else has results, that would be great.

1

Found a much easier solution that works on Monterey

  1. Disable the process using launchctl
launchctl disable user/$UID/com.apple.photoanalysisd
  1. Now kill the current Photoanalysisd process
launchctl kill SIGTERM gui/$UID/com.apple.photoanalysisd

and that should be it! Photoanalysisd should be disabled and no longer running in the background.

To re-enable it, run

launchctl enable user/$UID/com.apple.photoanalysisd
launchctl kickstart gui/$UID/com.apple.photoanalysisd
1
  • This works on Catalina as well
    – Andrew
    Commented Feb 1, 2023 at 11:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .