4

AppleScript を使用して iPhoto で行う必要があることを実行するためのヒントを Google で探していますが、これまでのところ、多くの情報は見つかりませんでした。さまざまな古いバージョンの 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"役割を担っていますが、何を伝えたらよいかわかりません。ライブラリ内の写真の整理方法の階層が重要な場合:

  1. すべての写真は、イベントごとに時系列に編成されています。(イベントは私の主要な組織形態です。)
  2. かなりの数のアルバムがありますが、すべてがアルバムに入っているわけではありません。
  3. すべての誤った写真を含む 1 つのスマート アルバムがあります。もちろん、これは写真の説明に既知の文字列が存在することに基づいています。最終的なコードがこのスマート アルバム内の写真をループする場合は、スマート アルバムが反復される配列を変更している可能性があるため、覚えておく必要があると思います。

私を動かすのに役立つリファレンスやサンプルコードはありますか? 逆に、この 1 回限りの大量修正を行うためのより良い方法を知っている人はいますか?

編集:次のコードでテストを実行しました:

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. そして、おそらく実行中にしばらくの間何か他のことをしてください:)

4

2 に答える 2

4

これが「ブルートフォース」バージョンです。これにより、すべての写真がループされます。必要に応じて、特定のアルバムに制限することで、これをよりエレガントにすることができます.

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
于 2011-01-17T14:25:30.823 に答える
1

これはどうですか。影響を与えたいアイテムのアルバムまたはスマート アルバムを作成する必要がありますが、これはとにかく破壊的ではありません。

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
于 2012-07-03T02:28:23.733 に答える