Search code examples
macosapplescriptphotos

How do I create/make an album in a named folder in OSX Photos with AppleScript?


I am looking for a solution whereby I can run an AppleScript locally to take a bunch of photos that are in Smart Folders in OSX Photos app and put them in non-smart equivalents. I found a script that largely does this:

on run {input, parameters}
    tell application "Photos"
        get folder "Managing the library"
        set smartAlb to album "Measurements"
        set regAlbName to "Measurements-Static"
        tell album regAlbName to if exists then delete
        set regAlb to make new album named regAlbName
        add (get media items of smartAlb) to regAlb
    end tell
end run

However, while I can set the folder of where to get the info from, the new album is created at the top level in Photos. All I am after is a tweak to the code shown to ensure that the new album is created in the same folder (currently called 'Managing the Library'). I've tried all sorts but I am not a regular AppleScript user, and couldn't find an answer online.

Appreciate any help people can provide :)


Solution

  • You have to add the location information where to create the new folder. Instead of just getting the folder Managing the library assign the reference to a variable and pass it in the make new album line.

    on run {input, parameters}
        tell application "Photos"
            set manageFolder to folder "Managing the library"
            set smartAlb to album "Measurements"
            set regAlbName to "Measurements-Static"
            tell album regAlbName to if exists then delete
            set regAlb to make new album named regAlbName at manageFolder
            add (get media items of smartAlb) to regAlb
        end tell
    end run