Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript Export Photo Albums to Folders

I'm having some trouble with this Applescript, but it's the only way so far that I can figure out to export my smart albums to a directory structure. It works sometimes, but much more often than not, I am met with this error:

MacBook Pro 13", macOS 10.14

Posted on Jun 23, 2019 7:19 PM

Reply
Question marked as Best reply

Posted on Jun 27, 2019 7:13 PM

Thanks for the reply...the script I'm using is #11: Export Albums to Folders - it sounds like that might be the answer, though I'm admittedly a little too green with Applescript to know where to place that block of code. The content of the script is below; any additional guidance appreciated!



-- modified by Leonie

-- to include a sorted list of albums to pick from

-- a dialog for the location of the default folder

-- a dialog to chose between exporting the originals or the modified versions

-- a prompt withe the list of the exported album names


on sortList(theList)

-- from: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html

set theIndexList to {}

set theSortedList to {}

try

repeat (length of theList) times

set theLowItem to ""

repeat with a from 1 to (length of theList)

if a is not in theIndexList then

set theCurrentItem to item a of theList as text

if theLowItem is "" then

set theLowItem to theCurrentItem

set theLowItemIndex to a

else if theCurrentItem comes before theLowItem then

set theLowItem to theCurrentItem

set theLowItemIndex to a

end if

end if

end repeat

set end of theSortedList to theLowItem

set end of theIndexList to theLowItemIndex

end repeat

on error errMsg number errorNumber

return {"An unknown error occurred:"} & theSortedList

end try

return theSortedList

end sortList


-- select the destination folder -- Leonie

set destination to choose folder with prompt "Select a destination folder to save the albums to" default location (the path to the desktop folder as alias)

set dest to ((the POSIX path of destination) as text) as POSIX file as text


-- set dest to "/Users/Jobs/Pictures/Albums/" as POSIX file as text -- the destination folder (use a valid path). -- change this to your default path for a fixed folder


-- Display a dialog to select the original images or the edited versions


set r to display dialog "Do you want to export the originals or the edited versions?" buttons {"Originals", "Edited versions"} default button 1 with icon 2

set orig to (button returned of r is "Originals")


tell application "Photos"

activate

set unsorted to (name of albums)


end tell


set l to sortList(unsorted) -- Leonie


set albNames to choose from list l with prompt "Select some albums" with multiple selections allowed



tell application "Photos"

if albNames is not false then -- not cancelled

repeat with tName in albNames

set tFolder to dest & tName

my makeFolder(tFolder) -- create a folder named (the name of this album) in dest

if orig then

export (get media items of album tName) to (tFolder as alias) with using originals -- export the original versions

else

export (get media items of album tName) to (tFolder as alias) without using originals -- export the edited versions

end if


end repeat

end if

end tell


tell application "Finder"

open (tFolder as alias)

return {"Done: "} & albNames

end tell


on makeFolder(tPath)

do shell script "mkdir -p " & quoted form of POSIX path of tPath

end makeFolder

Similar questions

5 replies
Question marked as Best reply

Jun 27, 2019 7:13 PM in response to Camelot

Thanks for the reply...the script I'm using is #11: Export Albums to Folders - it sounds like that might be the answer, though I'm admittedly a little too green with Applescript to know where to place that block of code. The content of the script is below; any additional guidance appreciated!



-- modified by Leonie

-- to include a sorted list of albums to pick from

-- a dialog for the location of the default folder

-- a dialog to chose between exporting the originals or the modified versions

-- a prompt withe the list of the exported album names


on sortList(theList)

-- from: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html

set theIndexList to {}

set theSortedList to {}

try

repeat (length of theList) times

set theLowItem to ""

repeat with a from 1 to (length of theList)

if a is not in theIndexList then

set theCurrentItem to item a of theList as text

if theLowItem is "" then

set theLowItem to theCurrentItem

set theLowItemIndex to a

else if theCurrentItem comes before theLowItem then

set theLowItem to theCurrentItem

set theLowItemIndex to a

end if

end if

end repeat

set end of theSortedList to theLowItem

set end of theIndexList to theLowItemIndex

end repeat

on error errMsg number errorNumber

return {"An unknown error occurred:"} & theSortedList

end try

return theSortedList

end sortList


-- select the destination folder -- Leonie

set destination to choose folder with prompt "Select a destination folder to save the albums to" default location (the path to the desktop folder as alias)

set dest to ((the POSIX path of destination) as text) as POSIX file as text


-- set dest to "/Users/Jobs/Pictures/Albums/" as POSIX file as text -- the destination folder (use a valid path). -- change this to your default path for a fixed folder


-- Display a dialog to select the original images or the edited versions


set r to display dialog "Do you want to export the originals or the edited versions?" buttons {"Originals", "Edited versions"} default button 1 with icon 2

set orig to (button returned of r is "Originals")


tell application "Photos"

activate

set unsorted to (name of albums)


end tell


set l to sortList(unsorted) -- Leonie


set albNames to choose from list l with prompt "Select some albums" with multiple selections allowed



tell application "Photos"

if albNames is not false then -- not cancelled

repeat with tName in albNames

set tFolder to dest & tName

my makeFolder(tFolder) -- create a folder named (the name of this album) in dest

if orig then

export (get media items of album tName) to (tFolder as alias) with using originals -- export the original versions

else

export (get media items of album tName) to (tFolder as alias) without using originals -- export the edited versions

end if


end repeat

end if

end tell


tell application "Finder"

open (tFolder as alias)

return {"Done: "} & albNames

end tell


on makeFolder(tPath)

do shell script "mkdir -p " & quoted form of POSIX path of tPath

end makeFolder

Jun 28, 2019 2:15 PM in response to adamfromtempe

Well, some assembly is required.


You should run your script in the script editor and see where it is taking too long.



click on the "lined paper" . This shows you the log. You will see every call to an external program. See where you get the error message. put timeout block around the statement.



click on the dark triangle to run your script.


Here is an example of what you will see:


Jun 24, 2019 10:55 AM in response to adamfromtempe

Well, you don't say specifically which script you're running - your link points to an index of dozens of scripts - so it's impossible to tell you exactly what to change.


However, in general, AppleScript has an internal timeout that it uses for any single command given to an application. If the command takes too long it's assumed to have failed, and AppleScript terminates to save you from waiting forever for a broken script that will never end.


The situation you're in, though, sounds like you have so many photos that each export is taking longer than AppleScript's timer, and so it terminates on you.


Fortunately, Apple predicted this possibility, so it allows you to override the default timeout.


Just wrap the errant lines in a 'timeout' block:


with timeout of 600 seconds

-- lenghty statement goes here

end timeout


this will allow the slow command to take up to 10 minutes before AppleScript pulls the cord.


Note that each statement within the block has the new timeout as its limit, not all the statements combined (i.e. if there are three statements in the block, then each command could take 9:59 and the timeout would not trigger).


Taking a guess at which script you're running, you probably just need to edit the line:


export (get media items of album tName) to (tFolder as alias) without using originals

to say:

with timeout of 30 * 60 seconds -- is 30 minutes enough?

export (get media items of album tName) to (tFolder as alias) without using originals

end timeout


Applescript Export Photo Albums to Folders

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.