Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active November 10, 2024 21:34
Show Gist options
  • Save huksley/564be2c903312bcee7dffe415d128f90 to your computer and use it in GitHub Desktop.
Save huksley/564be2c903312bcee7dffe415d128f90 to your computer and use it in GitHub Desktop.
Disabling photoanalysisd

For what it's worth (and with all the usual disclaimers about potentially making your mac unstable by disabling system services), here's some commands that will manipulate this service and services like it. Note the $UID in the command, that's just a bash shell variable that will resolve to some number. That's your numeric UID. You just run these commands from a Terminal command line. No special privileges needed.

If you want to disable it entirely, the first command stops it from respawning, and the second kills the one that is currently running:

launchctl disable gui/$UID/com.apple.photoanalysisd
launchctl kill -TERM gui/$UID/com.apple.photoanalysisd

(If you kill it without disabling it will die, but a new one will respawn and pick up where the old one left off)

I don't have this problem myself, so I can't try these next two commands. They're relying on good ole UNIX signals. You could theoretically suspend and resume the process like this ("STOP" and "CONT" are stop and continue):

launchctl kill -STOP gui/$UID/com.apple.photoanalysisd
launchctl kill -CONT gui/$UID/com.apple.photoanalysisd

I don't know what launchd does when running processes are suspended for a long time. Will it detect them as dead and kill and restart them? I dunno. But I do know they won't get any CPU time.

@kellyolivier
Copy link

Mine didnt go away till I closed preview. Seems like that might count now

@ElectronHerder
Copy link

ElectronHerder commented Nov 25, 2020

This piece of image recognition spyware, introduce by Apple, is harder than ever to get rid of in OS Catalina. The instructions for previous versions of MacOS worked. Apple apparently reads our solutions to this nightmare of a problem then figures out new ways to prevent us from stopping it. So, here's what I am doing and it appears it may work. I'm moving the .plist file to the LaunchAgentsIgnored directory OR just moving it to a whole different part of the filesystem.

I'm moving the relevant files to a folder in my Documents directory called Evilstuff.

You must have ROOT user enabled on your system for this to work.

Deactivate System Integrity Protection

1) Turn off the Mac
2) Hold down Command-R for about ten seconds and press power button
3) Wait for OS X to boot into the OS X Utilities Window
4) Choose Utilities -> Terminal
5) # csrutil disable
6) # reboot

Remove or rename the photoanalysisd file

# su
# mount -uw /
# mv -v /System/Library/LaunchAgents/com.apple.photoanalysisd.plist /Users/[myusername]/Documents/Evilstuff
# mv -v /System/Library/PrivateFrameworks/PhotoAnalysis.framework/Versions/A/Support/photoanalysisd /Users/[myusername]/Documents/Evilstuff

Reactivate System Integrity Protection

1) Turn off the Mac
2) Hold down Command-R for about ten seconds and press power button
3) Wait for OS X to boot into the OS X Utilities Window
4) Choose Utilities -> Terminal
5) # csrutil enable
6) # reboot

I am going to watch and see if it comes back. It is sure to do so, with the next update/patch from Apple, so I'm keeping these instructions handy.

@maxim-uvarov
Copy link

maxim-uvarov commented Jan 17, 2021

I'm testing another solution that I found on StackExchange

  1. start Photos, let it continue past the first dialogue box;
  2. now Preferences in the app menu is clickable (it wasn't before);
  3. Preferences > General , and untick both check boxes in Memories;
  4. close Photos.
    This stops photoanalysisd cold, no reboot or kill required.

Upd: The process became less voracious, but still it consumes cpu time

@dakworks
Copy link

I'm testing a composite of solutions, since none of the above are idea. I noticed that there's a delay element available in the plist. Until I have a chance to reboot the machine into Systems Integrity Protection off, I'm doing this:

su
while true do
    killall photoanalysisd
    sleep 10
done

which keeps the beast quiet until I figure it out.

@dakworks
Copy link

And the delay does nothing, as that's for launchd and it doesn't use launchd for its looping behaviour. SIGH.

The permanent fix:
https://apple.stackexchange.com/questions/338001/how-to-prevent-the-photos-app-from-launching-cloudphotosd-photoanalysisd-etc/413685#413685

@girafi
Copy link

girafi commented Feb 15, 2021

The solution from @ElectronHerder worked for me eventually.
Many thanks for giving me back the peace of a calm and not-glowing macbook.

Except for the "su" command. This command always yielded "Sorry". Then I read somewhere that the root user was protected on Mac OS X.
Use "sudo su -" instead, if you have the same issue.

@magJ
Copy link

magJ commented Mar 28, 2021

You can get your $UID by running id.
$UID was not a set environment variable for me in my terminal.

@marcosbrasil
Copy link

I have 0 (ZERO) photos in my library. I don't use photos or even iCloud Drive for photos storage in any way. Even after reinstall Catalina the problema persists. This thread are kept in my favorites forever.

So many thanks to @huksley , the sub reddit and stackexchange.

@nitantsoni
Copy link

nitantsoni commented Jul 9, 2022

Small change needed for Monterey. The command to disable the service is now

launchctl disable user/$UID/com.apple.photoanalysisd

The gui changed to user. The command to kill the process is the same

launchctl kill TERM gui/$UID/com.apple.photoanalysisd

@RCurious
Copy link

RCurious commented May 15, 2023

I don’t know about the “tracked” part but “ somebody “ left a mighty big (nearly 16 MB) footprint!!!

Powerstats for: photoanalysisd [1389]
UUID:
EE+**++-346A-388F-@@++
Path:
/System/Library/PrivateFrameworks/PhotoAnalysis.framework/Support/photoanalysisd
Resource Coalition ID: 4((
Architecture:
arm64e
Parent:
UNKNOWN [11
UID:
5&1
Sudden Term:
Tracked (allows idle exit)
Footprint:
12.16 MB -> 15.70 MB (+3632 KB)
Pageins:
273 pages
Start time:
2023-05-12 01:34:49.369 -0500
End time:
2023-05-12 01:37:01.563 -0500
Num samples:
39 (89%)
Primary state: 34 samples Non-Frontmost App, Non-Suppressed, User mode, Effective Thread QoS Background, Requested
Thread QoS Background, Override Thread QoS Unspecified
User Activity: 39 samples Idle, O samples Active
Power Source:
O samples on Battery, 39 samples on AC

@mailinglists35
Copy link

on monterey I need to periodically run the kill command. If I only kill it once, it starts again in about one minute. I did setup a crontab job where I run this script:

*/1 * * * * /Users/mac/stopmediaanalysisd.sh

% cat /Users/mac/stopmediaanalysisd.sh
for i in 1 2 3 4 5 6; do 
launchctl disable user/501/com.apple.photoanalysisd
launchctl disable user/501/com.apple.mediaanalysisd
launchctl kill INT gui/501/com.apple.photoanalysisd
launchctl kill INT gui/501/com.apple.mediaanalysisd
sleep 9
done

then check logs to see it gets terminated. note the kind termination SIGINT signal.
% log stream --predicate 'subsystem == "com.apple.duetactivityscheduler"' | grep --line-buffered RUN | grep --line-buffered media

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment