如何使用 Applescript 将图片导入 Photos.app

How to import picture to Photos.app with Applescript

set oldPath to "/Users/user/Desktop/aaaa/1110.jpg"
set thisPOSIXPath to (the POSIX path of oldPath)


set imageList to {}
copy thisPOSIXPath to the end of imageList


tell application "Photos"
    import imageList into container named "MyPictures"
end tell

我使用上面的脚本将一张图片导入到照片中,但是照片显示错误 "Unable to get metadata" 而 运行。我的脚本怎么了,谁知道如何将一张图片导入照片?

[编辑] 我找到了正确的方法

set filePath to POSIX file "/Users/user/Desktop/aaaa/1110.jpg"

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


tell application "Photos"
    import imageList into container named "MyPictures"
end tell

Photos.app 需要一个别名说明符列表作为导入命令的参数。

path to desktop是当前用户桌面文件夹的相对路径
as text 将别名说明符强制为 HFS 路径(以冒号分隔)。
用大括号包裹对象 {} 将对象强制转换为列表。

set filePath to alias ((path to desktop as text) & "aaaa:1110.jpg")
tell application "Photos"
    import {filePath} into container named "MyPictures"
end tell