Hi,
lloydfromchristchurch wrote:
is it possible to only export one nominated folder which has many folders and albums within it as apposed to exporting the whole library?
To export the structure from a nominated folder, use this script:
set dest to "/Users/me/Desktop/photos-Albums/" as POSIX file as text -- the destination folder (use a valid path)
tell application "Photos"
set thisFolder to folder "some unique name" -- the nominated folder
my exportAlbumsFromThisFolder(thisFolder, dest)
end tell
on exportAlbumsFromThisFolder(thisFolder, f) -- parameters of this handler: the folder in "Photos", the folder in the Finder
tell application "Photos"
repeat with thisAlbum in (get albums of thisFolder) -- albums of this folder
set tFolder to (f & (get name of thisAlbum))
my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
with timeout of 600 seconds
export (get media items of thisAlbum) to (tFolder as alias) without using originals
end timeout
end repeat
-- recursively descends the folder tree, because the loop call this handler
repeat with thisSubFolder in (get folders of thisFolder) -- sub-folders in this folder
set tFolder to f & (get name of thisSubFolder) & ":"
my makeFolder(tFolder) -- create a folder named (the name of this sub-folder) in dest
my exportAlbumsFromThisFolder(thisSubFolder, tFolder) -- call this handler
end repeat
end tell
end exportAlbumsFromThisFolder
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder
----
lloydfromchristchurch wrote:
Also is it possible to rename the photos to run in a consecutive number range starting at "1" for each album as the photos are sorted in each album?
To rename the photos, use this script:
set dest to "/Users/me/Desktop/photos-Albums/" as POSIX file as text -- the destination folder (use a valid path)
tell application "Photos"
set thisFolder to folder "some unique name" -- the nominated folder
my exportAlbumsFromThisFolder(thisFolder, dest)
end tell
on exportAlbumsFromThisFolder(thisFolder, f) -- parameters of this handler: the folder in "Photos", the folder in the Finder
tell application "Photos"
repeat with thisAlbum in (get albums of thisFolder) -- albums of this folder
set tFolder to (f & (get name of thisAlbum))
my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
with timeout of 600 seconds
export (get media items of thisAlbum) to (tFolder as alias) without using originals
end timeout
my renameFiles(get filename of media items of thisAlbum, tFolder)
end repeat
-- recursively descends the folder tree, because the loop call this handler
repeat with thisSubFolder in (get folders of thisFolder) -- sub-folders in this folder
set tFolder to f & (get name of thisSubFolder) & ":"
my makeFolder(tFolder) -- create a folder named (the name of this sub-folder) in dest
my exportAlbumsFromThisFolder(thisSubFolder, tFolder) -- call this handler
end repeat
end tell
end exportAlbumsFromThisFolder
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder
on renameFiles(namesList, f) --rename starting at 1, the order is the sorted photos in the album
set tCount to count namesList
set thisFolder to f as alias
tell application "System Events"
repeat with i from 1 to tCount
try
set thisFile to file (item i of namesList) of thisFolder
set theExt to name extension of thisFile
set name of thisFile to ("" & i & "." & theExt)
on error number n
if n = -1728 then -- no file with this name , maybe a file with the same name (Photos append " (1)" to the filename)
set baseName to text 1 thru -((count theExt) + 2) of (item i of namesList) -- name without the extension
repeat with j from 1 to 5
set tName to (baseName & " (" & j & ")." & theExt)
if exists (file tName of thisFolder) then
set name of file tName of thisFolder to ("" & i & "." & theExt)
exit repeat
end if
end repeat
end if
end try
end repeat
end tell
end renameFiles