AppleScript:将所选目录导入照片中的相册

AppleScript: Importing selected directories into albums in Photos

我正在尝试创建一个脚本,用于在 Yosemite 的照片中将目录导入为相册。

activate application "SystemUIServer"
tell application "Finder"
    activate
    repeat with flder in (get selection as alias list)
        set albumName to name of flder
        tell application "Photos"
            make new album named albumName

            set imageList to {}
            repeat with i from 1 to number of items in flder
                set this_item to item i of flder as alias
                set the end of imageList to this_item
            end repeat

            import imageList into album albumName
        end tell
    end repeat
end tell

根据我的发现,这应该有效——但无效:

error "Photos got an error: 
     Can’t make alias \"Macintosh HD:Users:knyttl:Pictures:archive:2014:01_prom:\" into type specifier." number -1700 
     from alias "Macintosh HD:Users:knyttl:Pictures:archive:2014:01_prom:" to specifier

它在 repeat 部分对 number 进行了补充。我什至不确定语法是否正确——在某些地方我看到 number 在其他一些地方 count,在其他一些地方以完全不同的方式对文件进行迭代。我很乐意提供任何帮助。

主要问题是在收集实际上是 Finder 术语的文件夹项目时 Photos 告诉块中的术语冲突。

试试这个,我分开了应用程序告诉块以分别扭曲特定术语。

activate application "SystemUIServer"
tell application "Finder" to set folderList to selection
repeat with aFolder in folderList
    set albumName to name of aFolder
    tell application "Photos" to set newAlbum to make new album named albumName
    set imageList to {}
    repeat with i from 1 to number of items in aFolder
        set this_item to item i of aFolder as alias
        set the end of imageList to this_item
    end repeat
    tell application "Photos" to import imageList into newAlbum
end repeat

或更容易

activate application "SystemUIServer"
tell application "Finder" to set folderList to selection
repeat with aFolder in folderList
    tell application "Finder"
        set albumName to name of aFolder
        set imageList to files of aFolder as alias list
    end tell
    tell application "Photos"
        set newAlbum to make new album named albumName
        import imageList into newAlbum
    end tell
end repeat

同意,分离照片和 Finder tell 块似乎是个问题。

这是我开始工作的,同时测试了多个文件夹:

tell application "Finder"
    activate
    repeat with flder in (get selection)
        set albumName to name of flder
        set imageList to {}
        repeat with i from 1 to (count of items of flder)
            set photo to item i of flder
            set the end of imageList to photo as alias
        end repeat

        tell application "Photos"
            set newAlbum to make new album named albumName
            import imageList into newAlbum
        end tell
    end repeat
end tell