Commit 6a6e6cd4 authored by Henry Kautz's avatar Henry Kautz

Upload New File

parent 17334a0f
use script "Photos Utilities"
use scripting additions
set ignoreList to {"Videos", "All Photos", "Faces", "Last Import", "Bursts", "Recently Deleted"}
set badalbums to ""
set source to my choosePhotosFolder()
set dest to (choose folder with prompt "Choose destination folder") as text
set sourceFolders to item 1 of source
set sourceAlbums to item 2 of source
repeat with a in sourceAlbums
if ignoreList does not contain name of a then
my myExportPhotoAlbum(a, dest)
end if
end repeat
repeat with f in sourceFolders
my myExportPhotoFolder(f, dest)
end repeat
display alert "Finished export. Errors occurred when exporting" & badalbums
on myExportPhotoFolder(i, dir)
display alert "Exporting Folder " & (get name of i) giving up after 2
tell application "Photos"
set subdir to dir & (get name of i) & ":"
my makeFolder(subdir)
repeat with a in albums of i
my myExportPhotoAlbum(a, subdir)
end repeat
repeat with f in folders of i
my myExportPhotoFolder(f, subdir)
end repeat
end tell
end myExportPhotoFolder
on myExportPhotoAlbum(a, dir)
display alert "Exporting Album " & (get name of a) giving up after 2
tell application "Photos"
set subdir to dir & (get name of a)
try
with timeout of 7200 seconds
set newfolder to sequentially named export of (get media items of a) separator "-" base name (get name of a) without resulting file references
end timeout
on error
display alert "Failed to export all images in " & (get name of a) giving up after 2
badalbums = badlbums & return & (get name of a)
end try
with timeout of 7200 seconds
set destFolder to quoted form of POSIX path of subdir
do shell script "if [-e " & destFolder & "]; then rm -rf " & destFolder & "; fi"
do shell script "mv -f " & quoted form of POSIX path of newfolder & " " & destFolder
end timeout
end tell
end myExportPhotoAlbum
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder
on choosePhotosFolder()
tell application "Photos"
set folderNames to names of top level folders
set albumNames to names of top level albums
end tell
set folderNames to my simple_sort(folderNames)
set albumNames to my simple_sort(albumNames)
set itemNames to folderNames & albumNames
set exportItemNames to (choose from list itemNames with prompt "Select albums and folders" with multiple selections allowed)
if exportItemNames is false then
quit
end if
set exportFolders to {}
set exportAlbums to {}
repeat with i from 1 to count of exportItemNames
set f to item i of exportItemNames
if folderNames contains f then
set end of exportFolders to top level folder named f
else if albumNames contains f then
set end of exportAlbums to top level album named f
end if
end repeat
return {exportFolders, exportAlbums}
end choosePhotosFolder
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment