2011-01-16 5 views
4

나는 AppleScript로 iPhoto에서해야 할 일을 수행 할 수있는 몇 가지 지침을 찾기 위해 Google을 통해 둘러 보았지만 아직까지는 많이 찾지 못했습니다. iPhoto의 다양한 구버전 버전의 스크립트에 대한 여러 가지 오래된 논의가 있지만, 필자에게 필요한 것은별로 도움이되지 못했습니다. 기본적으로 의사 코드에서, 나는이 일을 찾고 있어요 :iPhoto 자동화를위한 AppleScript 구문

입니다
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. 모든 잘못된 사진이 포함 된 하나의 스마트 앨범이 있습니다. 이것은 물론 사진 설명에 알려진 문자열의 존재를 기반으로합니다. 스마트 앨범이 반복되는 배열을 바꿀 수 있기 때문에 최종 코드가이 스마트 앨범의 사진을 통해 반복되는 경우 염두에 두어야 할 필요가 있다고 생각합니까?

아무에게도 나에게 도움이되는 참조 또는 샘플 코드가 있습니까? 반대로,이 일회성 대량 수정을 수행하는 더 좋은 방법을 알고있는 사람이 있습니까?

편집 : 나는 다음 코드를 사용하여 테스트를 실행 : 다음과 같은 출력 결과

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

다음은 '무차별 대입'버전입니다. 이렇게하면 마다 사진이 반복됩니다. 원한다면 특정 앨범으로 제한하여 더 우아하게 만들 수 있습니다.

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 
+0

@ dscl : 조건부의 첫 번째 캐치 이후에 'exit repeat'을 사용하여 테스트를 실행했지만 오류가 발생합니다. 질문에 이벤트 결과를 추가합니다. 어쩌면'comment'는 대신'description'과 같은 것이어야합니까?아마도'comment'는 제가 찾고있는 텍스트 필드를 가지고있는 객체일까요? – David

+0

@ david : 어떤 iPhoto 버전을 사용하고 있습니까? 그들은 내가 테스트 한 버전에서 이름을 변경했을 수도 있습니다. – dscl

+0

@ dscl : '11 (최근에 '08에서 새 앱 스토어로 업그레이드되었으므로 라이브러리는 원래 '08 '이었습니다.) – David

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