繁体   English   中英

循环浏览照片中的每张照片

[英]Loop through every photo in Photos

我想清理我的照片库,特别是将我的所有iPhone屏幕截图移动到一个新专辑,这样我就可以轻松浏览它们并删除我想要的内容。

现在为此我首先想在照片中制作一张智能相册,但似乎照片无法过滤图像的尺寸,所以我启动了AppleScript编辑器:)。

我创建了以下脚本,该脚本适用于我创建的“测试相册”:

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 media items in source_albumrepeat 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

-10000错误是由于照片1.0中的错误引起的。 我已将此作为雷达20626449提交给Apple(在OpenRadar上http://openradar.appspot.com/radar?id=6090497735000064 )。 错误是间歇性的,但库中的照片越多,在任何给定的脚本命令上发生的可能性就越大。

没有完全可靠的方法来解决错误,但有一件事似乎有帮助,如果在启动脚本之前在照片中选择了“所有照片”相册。 不幸的是,Photos AppleScript套件无法选择相册,因此您需要在启动脚本之前手动执行此操作。

不确定你是否介意在终端中放入shell,或者如果你可以使用iPhoto,但如果可以,这可能会让你开始寻找你的HOME目录及其下面的所有文件,即PNG和那个符合你的尺码......

#!/bin/bash
isIphone() {
   # Get width using sips, don't bother getting height if not 640 wide
   w=$(sips -g pixelWidth  "$1" | awk 'END{print $2}')
   [ "$w" != "640" ] && return
   # Get height using sips, just return if not iPhone size
   h=$(sips -g pixelHeight "$1" | awk 'END{print $2}')
   [ $h != "1136" ] && return
   # Output image size and name
   echo $w,$h, $1
}

# Go through all PNG files in HOME directory listing iPhone-sized ones
find ~ -iname "*.png" -type f -print0 | while read -d $'\0' -r file ; do isIphone "$file"; done

产量

640,1136, ./iPhone/2013 09 iPhone/IMG_0269.PNG
640,1136, ./iPhone/2013 09 iPhone/IMG_0363.PNG
640,1136, ./iPhone/2013 09 iPhone/IMG_0376.PNG

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM