I am (very) new to Applescript.
I want to create a script taking album, filename, keyword as a parameter and
tag the file with given keyword in OSX Catalina Photos app.
Any guidance would be welcomed.
JY
I am (very) new to Applescript.
I want to create a script taking album, filename, keyword as a parameter and
tag the file with given keyword in OSX Catalina Photos app.
Any guidance would be welcomed.
JY
Hi,
It would be necessary to read a little first and start at least some kind of code.
The question was asked incorrectly because in Photos.app the files are not albums, but media items (that is, concrete photos). You can get a list of all these photos with their full paths like this:
set aFolder to alias (((path to pictures folder) as text) & "Photos Library.photoslibrary:originals")
tell application "Finder"
set originals to (every file of every folder of aFolder) as alias list
end tell
Now that you have full references to your photos, you can use the usual tag binding sript.
Full example:
use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
property |NSURL| : a reference to |NSURL| of current application
property NSURLTagNamesKey : a reference to NSURLTagNamesKey of current application
property aFolder : alias (((path to pictures folder) as text) & "Photos Library.photoslibrary:originals")
tell application "Finder"
set originals to (every file of every folder of aFolder) as alias list
set FinderIDs to name of every file of every folder of aFolder
end tell
tell application "Photos"
set alexandraPhotosIds to id of every media item of album "Alexandra"
repeat with alexandraPhotosId in alexandraPhotosIds
set contents of alexandraPhotosId to text 1 thru 36 of alexandraPhotosId
end repeat
end tell
repeat with i from 1 to count originals
set FinderID to text 1 thru 36 of item i of FinderIDs
set original to item i of originals
if FinderID is in alexandraPhotosIds then my setTag(original, "From album \"Alexandra\"")
end repeat
on setTag(aFile as alias, theTag as text)
set tagList to {theTag}
set aURL to |NSURL|'s fileURLWithPath:(POSIX path of aFile) -- make URL
aURL's setResourceValue:tagList forKey:NSURLTagNamesKey |error|:(missing value)
end setTag
One more time you assume that everybody use English which HAPPILY isn’t true.
It’s reall boring to read such frequent rude wrong statements.
On system using French, the photos of the application “Photos” are stored in “Albums”
Here is the list of resources used in three operating systems.
Everybody will see that, in English too, the application “Photos” store its pictures in containers named Albums !
theValue theKey auxValue HfsPath
Mes Albums MyAlbums My Albums resources YK:resources trois:Catalina:Applications:Photos.app:Contents:Resources:fr.lproj:IPXAlbum.strings
Mes Albums IPXUserAlbumsSectionTitle My Albums resources YK:resources trois:Catalina:Applications:Photos.app:Contents:Resources:fr.lproj:IPXMain.strings
Mes Albums My Albums My Albums resources YK:resources trois:High Sierra:Applications:32 bits:iWeb.app:Contents:Resources:French.lproj:Localizable.strings
Mes albums FFMDPhotoAlbums My Albums resources YK:resources trois:High Sierra:Applications:iMovie.app:Contents:Frameworks:Flexo.framework:Versions:Current:Resources:fr.lproj:FFLocalizable.strings
Mes Albums MyAlbums My Albums resources YK:resources trois:High Sierra:Applications:Photos.app:Contents:Resources:fr.lproj:IPXAlbum.strings
Mes Albums IPXUserAlbumsSectionTitle My Albums resources YK:resources trois:High Sierra:Applications:Photos.app:Contents:Resources:fr.lproj:IPXMain.strings
Mes Albums SidebarMyAlbumsHeaderTitle My Albums resources YK:resources trois:High Sierra:Applications:Photos.app:Contents:Resources:fr.lproj:IPXSidebar.strings
Mes Albums MyAlbums My Albums resources YK:resources trois:Mojave:Applications:Photos.app:Contents:Resources:fr.lproj:IPXAlbum.strings
Mes Albums IPXUserAlbumsSectionTitle My Albums resources YK:resources trois:Mojave:Applications:Photos.app:Contents:Resources:fr.lproj:IPXMain.strings
Mes Albums SidebarMyAlbumsHeaderTitle My Albums resources YK:resources trois:Mojave:Applications:Photos.app:Contents:Resources:fr.lproj:IPXSidebar.strings
Just before posting I discover that, at last, you recognize that the app really use this kind of objects.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 21:18:34
Here is contents of Photo Library on new Catalina (folders):
database
external
originals <— Here
private
resources
For those who has the photos on other directory, it is simple editing property aFolder of my script. The script is one idea how to do the task, and not 1 script for all and for everything. I wrote above: example.
It’s not my imagination which wrote :
set alexandraPhotosIds to id of every media item of album “Alexandra”
In this instruction, the word album may not be replaced by an other one.
album is carefully described in the dictionary of the application:
album n [inh. container] : An album. A container that holds media items
elements
contains media items; contained by application.
-- with some relatives :
application n [see also Standard Suite] : The top level scripting object for Photos.
elements
contains containers, albums, folders, media items, moments.
properties
selection (list of media item, r/o) : The currently selected media items in the application
favorites album (album, r/o) : Favorited media items album.
last import album (album, r/o) : Last import album.
slideshow running (boolean, r/o) : Returns true if a slideshow is currently running.
recently deleted album (album, r/o) : The set of recently deleted media items
It’s exactly what was used by the OP.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 avril 2020 21:52:45