Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stlow

macrumors member
Original poster
Mar 31, 2020
39
29
I hope someone can help me out with this.

I have set up my photo library on an external drive that syncs to iCloud when I open the Photos app. Often times it doesn't start syncing by itself, so I found the very helpful tip to close Photos, quit certain processes in the Activity Monitor (see below) and restart Photos. It works every time, the Photos app starts syncing right away after that.
So now my question is: Is there a way to build an Apple Script that force quits these processes automatically?

The processes in question are:
- Photos Agent
- All processes containing the word "photos" (e.g. com.apple.CloudPhotosConfiguration)

I'm on a MacBook Pro Late 2011 with High Sierra.
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751
You can use a simple command file, something like this
Code:
#!/bin/bash
killall Photos
killall com.apple.CloudPhotosConfiguration

open -a /Applications/Photos.app
use killall for all the processes you want to quit, copy-paste the code into TextEdit, save it as Photos.command on your Desktop, then run in Terminal chmod +x ~/Desktop/Photos.command to make it executable. Now all you have to do is duble-click it anytime you want to restart Photos.
You can use the same code in AppleScript: do shell script "killall Photos"
 

stlow

macrumors member
Original poster
Mar 31, 2020
39
29
You can use a simple command file, something like this
Code:
#!/bin/bash
killall Photos
killall com.apple.CloudPhotosConfiguration

open -a /Applications/Photos.app
use killall for all the processes you want to quit, copy-paste the code into TextEdit, save it as Photos.command on your Desktop, then run in Terminal chmod +x ~/Desktop/Photos.command to make it executable. Now all you have to do is duble-click it anytime you want to restart Photos.
You can use the same code in AppleScript: do shell script "killall Photos"
Somehow I couldn't make it work. I managed to make an Apple Script work that quits the Photos app, kills all the background processes and restarts the Photos app.
Code:
tell application "System Events"
    set ExistingProcs to (name of every process)
end tell
if (ExistingProcs contains "Photos") then
    do shell script "killall Photos"
end if
if (ExistingProcs contains "cloudphotosd") then
    do shell script "killall cloudphotosd"
end if
if (ExistingProcs contains "Photos Agent") then
    do shell script "killall Photos Agent"
end if
if (ExistingProcs contains "com.apple.CloudPhotosConfiguration") then
    do shell script "killall com.apple.CloudPhotosConfiguration"
end if
if (ExistingProcs contains "com.apple.photos.ImageConversionService") then
    do shell script "killall com.apple.photos.ImageConversionService"
end if
if (ExistingProcs contains "com.apple.photos.VideoConversionService") then
    do shell script "killall com.apple.photos.VideoConversionService"
end if
delay 1
tell application "Photos"
    activate
end tell

Unfortunately the com.apple.... processes don't seem to quit, I'll have to see if that stops the sync from working.
I even managed to remap CMD+Q to run the script when I'm inside the Photos app using BetterTouchTool.
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751
Unfortunately the com.apple.... processes don't seem to quit, I'll have to see if that stops the sync from working.
I even managed to remap CMD+Q to run the script when I'm inside the Photos app using BetterTouchTool.
If the process is running as root, you have to use do shell with administrator privileges.
Code:
tell application "System Events"
    set ExistingProcs to (name of every process)
end tell
if (ExistingProcs contains "Photos") then
    do shell script "killall Photos"
end if
if (ExistingProcs contains "cloudphotosd") then
    do shell script "killall cloudphotosd"
end if
if (ExistingProcs contains "Photos Agent") then
    do shell script "killall Photos Agent"
end if
if (ExistingProcs contains "com.apple.CloudPhotosConfiguration") then
    do shell script "killall com.apple.CloudPhotosConfiguration" with administrator privileges
end if
if (ExistingProcs contains "com.apple.photos.ImageConversionService") then
    do shell script "killall com.apple.photos.ImageConversionService" with administrator privileges
end if
if (ExistingProcs contains "com.apple.photos.VideoConversionService") then
    do shell script "killall com.apple.photos.VideoConversionService" with administrator privileges
end if
delay 1
tell application "Photos"
    activate
end tell
You can tell if they have been restarted by watching the PID. If that nunber changes, the process has been restarted.
 

stlow

macrumors member
Original poster
Mar 31, 2020
39
29
If the process is running as root, you have to use do shell with administrator privileges.
Code:
tell application "System Events"
    set ExistingProcs to (name of every process)
end tell
if (ExistingProcs contains "Photos") then
    do shell script "killall Photos"
end if
if (ExistingProcs contains "cloudphotosd") then
    do shell script "killall cloudphotosd"
end if
if (ExistingProcs contains "Photos Agent") then
    do shell script "killall Photos Agent"
end if
if (ExistingProcs contains "com.apple.CloudPhotosConfiguration") then
    do shell script "killall com.apple.CloudPhotosConfiguration" with administrator privileges
end if
if (ExistingProcs contains "com.apple.photos.ImageConversionService") then
    do shell script "killall com.apple.photos.ImageConversionService" with administrator privileges
end if
if (ExistingProcs contains "com.apple.photos.VideoConversionService") then
    do shell script "killall com.apple.photos.VideoConversionService" with administrator privileges
end if
delay 1
tell application "Photos"
    activate
end tell
You can tell if they have been restarted by watching the PID. If that nunber changes, the process has been restarted.
I will check the PID numbers when I’m home tomorrow.
Can I make the Apple script use admin privileges to execute the commands?
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751

stlow

macrumors member
Original poster
Mar 31, 2020
39
29
You can put your username and password in and save the script as a Run-only application
Code:
do shell script "killall com.apple.photos.VideoConversionService" user name "UserName" password "password" with administrator privileges
https://developer.apple.com/library.../MacAutomationScriptingGuide/SaveaScript.html

I have tried putting in the administrator privileges, it still doesn't work for the com.apple... processes. The PID stays the same. When I force quit it in the Activity Monitor it actually quits and there's a new PID when I launch the Photos app.
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751
I have tried putting in the administrator privileges, it still doesn't work for the com.apple... processes. The PID stays the same. When I force quit it in the Activity Monitor it actually quits and there's a new PID when I launch the Photos app.
I'm not sure why you used tell application "System Events", why not just do shell script
Code:
try
    do shell script "killall Photos"
end try
try
    do shell script "killall cloudphotosd"
end try
try
    do shell script "killall Photos Agent"
end try
try
    do shell script "killall com.apple.CloudPhotosConfiguration" with administrator privileges
end try
try
    do shell script "killall com.apple.photos.ImageConversionService" with administrator privileges
end try
try
    do shell script "killall com.apple.photos.VideoConversionService" with administrator privileges
end try
delay 1
tell application "Photos"
    activate
end tell
 
Last edited:

stlow

macrumors member
Original poster
Mar 31, 2020
39
29
I'm not sure why you used tell application "System Events", why not just do shell script
Code:
try
    do shell script "killall Photos"
end try
try
    do shell script "killall cloudphotosd"
end try
try
    do shell script "killall Photos Agent"
end try
try
    do shell script "killall com.apple.CloudPhotosConfiguration" with administrator privileges
end try
try
    do shell script "killall com.apple.photos.ImageConversionService" with administrator privileges
end try
try
    do shell script "killall com.apple.photos.VideoConversionService" with administrator privileges
end try
delay 1
tell application "Photos"
    activate
end tell

It was a workaround I found in another forum to check which processes are actually running. The "try/end try" works as well, thank you. But it still doesn't kill the com.apple process. Is there another command I can try?
I ran the killall command in every possible way for com.apple.CloudPhotosConfiguration. The Activity Monitor shows that it keeps running, the PID stays the same. When I go into the Activity Monitor and force quit it, it quits right away and appears with a new PID as soon as I open the Photos app. How is this possible?
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751
It was a workaround I found in another forum to check which processes are actually running. The "try/end try" works as well, thank you. But it still doesn't kill the com.apple process. Is there another command I can try?
I ran the killall command in every possible way for com.apple.CloudPhotosConfiguration. The Activity Monitor shows that it keeps running, the PID stays the same. When I go into the Activity Monitor and force quit it, it quits right away and appears with a new PID as soon as I open the Photos app. How is this possible?
Try this version
Code:
try
    do shell script "killall Photos"
end try
try
    do shell script "killall cloudphotosd"
end try
try
    do shell script "killall Photos Agent"
end try
try
    do shell script "launchctl kickstart -k user/501/com.apple.CloudPhotosConfiguration" with administrator privileges
end try
try
    do shell script "launchctl kickstart -k user/501/com.apple.photos.ImageConversionService" with administrator privileges
end try
try
    do shell script "launchctl kickstart -k user/501/com.apple.photos.VideoConversionService" with administrator privileges
end try
delay 1
tell application "Photos"
    activate
end tell
 

cocoua

macrumors 6502a
May 19, 2014
926
538
madrid, spain
Hi, I'm looking to close com.apple.quicklook.ThumbnailsAgent which looks to need admin privileges, I'm using this script in automator in order to reset the preview icons that aren't working time to time in Finder (Monterey):



Code:
do shell script "killall com.apple.quicklook.ThumbnailsAgent" user name "****" password "********" with administrator privileges

do shell script "killall Finder"

2ed6e1fb-28d8-4814-9b9f-9d99dc216c3d




It worked the first time I tried, it wont now....

Finder reboots but the process still in Activity monitor , you can see the process won't quit (same PID).

No error message...

I tried with a delay 10 between but that doesnt makes any sense (and dont work either)
 

bogdanw

macrumors 603
Mar 10, 2009
5,718
2,751
Finder reboots but the process still in Activity monitor , you can see the process won't quit (same PID).
Try
Code:
do shell script "launchctl kickstart -k gui/501/com.apple.quicklook.ThumbnailsAgent" user name "***" password "***" with administrator privileges
 

solouki

macrumors 6502
Jan 5, 2017
339
213
Hi, it looks like you have found a solution, but I thought I'd still mention my experiences with "killall".

I have found that sometimes "killall" does not work as expected for some processes, but then sometimes if you specify the actual signal to send this often helps. For instance, I believe the default signal sent to the process is TERM, but I find the KILL signal to work in more cases (the KILL, or -9, signal is non-ignorable by the process), thus I typically use "killall -9" instead of just "killall".

I also find that sometimes "killall -9" does not work, but then often "pkill -9" will work. And yeah, I don't know and haven't investigated why one will work and one won't in certain circumstances.

I have also found "pgrep -l" useful for listing all PIDs associated with a process name.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.