Hello,
I have been having this issue for years with the newer versions of Photos without finding a solution other than "logging out of the other account", or "use an external drive", which are not satisfying solutions.
More than once, I thought that the photo library had been definitely corrupted by incorrect permissions and subsequent "repairs", and I have been glad to have a backup...
So I took a bit of time to try to solve it for good this afternoon, and I think I have succeeded. The only requirement is that the library must not be set as the system library. Well, actually it might even work with the system library, but I'd be cautious about it since there might be side effects and nobody wants to loose access to their photos.
So here are two automator apps that will do the following if the photo library ownership is not set to the current user:
- Quit the Photos application (even if it is running on another account)
- Quit the photolibraryd and photoanalysisd daemons/processes (even if they are running on other accounts), which are launched in the background with the Photos applcation and lock the photo library even after quitting the application. They are used for things like face recognition and cloud synchronisation.
- Set the ownership of all files in the photo library to the current user (suprisingly, this is what the Photos application will do to repair the library file permissions)
Finally, open the photo library with the Photos application.
As far as I can tell, they work well.
The first version uses AppleScript. This is probably the one you want to use, the only downside is that it will ask you for administrator password instead of using touchID.
The second version only uses zsh. It will not work unless you make changes to your system configuration, however if you do it will allow you to use touchID, which is more practical in the long run. For it to work, you need to enable touchID authentification for the sudo command. You can easily find ressources about this on the internet - for instance, have a look here for how to do it on Sonoma.
So without further rambling, here is the AppleScript version:
In the shell script action the code is just:
echo "$1"
There might be a more elegant way to perform text conversion but it works.
In the AppleScript action the code is:
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
on run {input, parameters}
set library to input as text
set library to findAndReplaceInText(library, " ", "\\ ")
set user to do shell script "echo $(whoami)"
set owner to do shell script "echo $(stat -f '%Su' " & library & ")"
if user ≠ owner then
do shell script "killall -q Photos; exit 0" with administrator privileges
do shell script "killall -q photolibraryd; exit 0" with administrator privileges
do shell script "killall -q photoanalysisd; exit 0" with administrator privileges
do shell script "chown -R " & user & " " & library with administrator privileges
end if
return input
end run
A rather long script, but most of the code is to handle text conversion.
You just need to customize the first action, by inputting the path to your library. Be careful about special characters in the library name or in the folders containing the library: spaces are handled by the script, but other special characters may fail (brackets, accented letters, etc...)
And here is the zsh version:
With the following code for the shell script action:
library=$1
user=$(whoami)
owner=$(stat -f '%Su' $library)
if [[ $user != $owner ]]; then
sudo killall -q Photos
sudo killall -q photolibraryd
sudo killall -q photoanalysisd
sudo chown -R $user $library
fi
echo $library
I hope that it will be useful to some people.