我一直在通过谷歌四处寻找一些指点,让我通过AppleScript在AppleScript上做一些我需要做的事情,但到目前为止还没有发现很多。对于各种旧版本的iPhoto,有各种各样的旧的脚本讨论,但是没有什么特别有助于我所需要的东西。基本上,在伪代码中,我希望这样做:
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"部分,但不知道该说什么。如果库中照片的组织方式的层次结构很重要:
。
有人有什么参考资料或样本代码来帮助我吗?相反地,有没有人知道一个更好的方法来做这个一次性的质量修正?
编辑:--我用以下代码运行了一个测试:
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这就产生了以下产出:
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编辑:,今天早上我有一些时间对它进行修补,看起来只需要一些类型的铸造。此代码现在正在成功地更改它找到的第一张匹配照片:
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。并且可能在运行时做一段时间其他的事情:)
发布于 2011-01-17 14:25:30
这是一个“蛮力”版本。这将遍历的每一张照片。如果你想的话,你可以通过限制某些专辑来使这更优雅。
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发布于 2012-07-03 02:28:23
那这个呢。您将需要制作一个相册或智能相册的项目,您希望影响,但这是较少的破坏性无论如何。
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 tellhttps://stackoverflow.com/questions/4708418
复制相似问题