【发布时间】:2015-05-02 04:26:32
【问题描述】:
我想清理我的照片库,特别是将我所有的 iPhone 屏幕截图移动到一个新相册中,这样我就可以轻松地浏览它们并删除我想要的内容。
为此,我首先想在 Photos 中制作一个智能相册,但似乎 Photos 无法过滤图像的尺寸,所以我启动了 AppleScript Editor :)。
我创建了以下脚本,它适用于我创建的“测试专辑”:
tell application "Photos"
set source_album_name to "Test Album"
set target_album_name to "Screenshots"
set target_width to 640
set target_height to 1136
if not (exists container named target_album_name) then
make new album named target_album_name
end if
set target_album to container target_album_name
set source_album to container source_album_name
set imageList to {}
repeat with photo in media items in source_album
if width of photo = target_width and height of photo = target_height then
set the end of imageList to photo
end if
end repeat
add imageList to target_album
end tell
此脚本循环遍历名为 Test Album 的相册,并将高度和宽度与 iPhone 5S 的尺寸进行比较。当它们匹配时,它会将照片添加到 Screenshots 库中。没有问题。
现在我想在我的整个照片集上运行这个脚本,所以我将repeat with photo in media items in source_album 更改为repeat with photo in every media item。
一旦超过第一项 (Photos got an error: Can’t get item 2 of every media item. Invalid index),就会产生错误。
之后我将代码更改为:
set all_images to every media item
repeat with photo in all_images
但在加载一段时间后,脚本以代码 -10000 退出,可能是因为该库中的照片数量 (27.000)。
有没有办法在这样的集合中分页?
编辑:更改set 行以包含更好的查询具有相同的效果,导致AppleEvent handler failed 错误号为-10000。
set all_images to every media item whose width = target_width and height = target_height
【问题讨论】:
-
every media item是否可能包括,比如音轨,它可能没有高度/宽度? -
嗯,它是媒体项目对象的一个属性,我猜这个值会是 0 或者至少不包含在查询中。但是当它崩溃时,我会尝试弄清楚。
-
问题是
width和height属性是整数,不能是missing value。 (也试过了,它在第一条记录处崩溃,整数到缺失值的转换错误)。
标签: macos applescript