首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于AppleScript自动化的iPhoto语法

用于AppleScript自动化的iPhoto语法
EN

Stack Overflow用户
提问于 2011-01-16 22:10:48
回答 2查看 5.3K关注 0票数 4

我一直在通过谷歌四处寻找一些指点,让我通过AppleScript在AppleScript上做一些我需要做的事情,但到目前为止还没有发现很多。对于各种旧版本的iPhoto,有各种各样的旧的脚本讨论,但是没有什么特别有助于我所需要的东西。基本上,在伪代码中,我希望这样做:

代码语言:javascript
复制
for each photo in library
  if photo.Description contains "a known string"
    photo.Description = photo.Description.Replace("a known string", "")
  end if
end for

也就是说,我有一个错误的文本,它已经进入我的图书馆的每一张(嗯,几乎每一张)照片。我猜我在过去的某个时候搞砸了一个批次的更改,直到现在才注意到。无论是这样,还是从iPhoto '08升级到'11,都是以某种方式实现的,无论是哪种方式,最终结果都是一样的。

我对AppleScript不太熟悉,很难找到合适的语法/词汇表。基本上,我在tell application "iPhoto"部分,但不知道该说什么。如果库中照片的组织方式的层次结构很重要:

  1. 每一张照片都是按时间顺序组织成事件的。(事件是我的主要形式的organization.)
  2. There是大量的相册,但并不是所有的都在一张相册中。
  3. 有一个智能相册,其中包含每一张错误的照片。)当然,这是基于照片描述中已知字符串的存在。因此,如果最终代码在这个智能相册中遍历照片,可能需要记住这一点,因为智能相册可能会更改正在迭代的数组,不?

有人有什么参考资料或样本代码来帮助我吗?相反地,有没有人知道一个更好的方法来做这个一次性的质量修正?

编辑:--我用以下代码运行了一个测试:

代码语言:javascript
复制
tell application "iPhoto"
    activate
    set thePhotos to get every photo
    repeat with aPhoto in thePhotos
        if aPhoto's comment contains "[known string]" then
            log aPhoto's comment
            tell aPhoto to set it's comment to text 1 thru (offset of "[known string]" in aPhoto's comment) of aPhoto's comment
            log aPhoto's comment
            exit repeat
        end if
    end repeat
end tell

这就产生了以下产出:

代码语言:javascript
复制
tell application "iPhoto"
    activate
    get every photo
    get comment of photo id 4.294977224E+9
    (*comment of photo id 4.294977224E+9*)
    offset of "[known string]" in comment of photo id 4.294977224E+9
    «event ascrgdut»
    offset of "[known string]" in comment of photo id 4.294977224E+9
end tell
tell current application
    offset of "[known string]" in «class pcom» of «class ipmr» id 4.294977224E+9
Result:
error "iPhoto got an error: Can’t make comment of photo id 4.294977224E+9 into type string." number -1700 from comment of photo id 4.294977224E+9 to string

编辑:,今天早上我有一些时间对它进行修补,看起来只需要一些类型的铸造。此代码现在正在成功地更改它找到的第一张匹配照片:

代码语言:javascript
复制
tell application "iPhoto"
    activate
    set thePhotos to get every photo
    repeat with aPhoto in thePhotos
        if aPhoto's comment contains "[known string]" then
            log aPhoto's comment as text
            set theComment to aPhoto's comment as text
            set theComment to text 1 thru (offset of "[known string]" in theComment) of theComment
            tell aPhoto to set it's comment to theComment
            log aPhoto's comment as text
            exit repeat
        end if
    end repeat
end tell

现在备份我的库并删除exit repeat。并且可能在运行时做一段时间其他的事情:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-01-17 14:25:30

这是一个“蛮力”版本。这将遍历的每一张照片。如果你想的话,你可以通过限制某些专辑来使这更优雅。

代码语言:javascript
复制
tell application "iPhoto"
    set thePhotos to get every photo
    repeat with aPhoto in thePhotos
        if aPhoto's comment contains "theString" then
            tell aPhoto to set it's comment to "newString"
        end if
    end repeat
end tell
票数 4
EN

Stack Overflow用户

发布于 2012-07-03 02:28:23

那这个呢。您将需要制作一个相册或智能相册的项目,您希望影响,但这是较少的破坏性无论如何。

代码语言:javascript
复制
tell application "iPhoto"
    activate
    set thePhotos to get every photo in current album whose comment contains "TEST123"
    repeat with aPhoto in thePhotos
        tell aPhoto to set it's comment to "123TEST"
    end repeat
end tell
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4708418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档