2011-08-25 4 views
1

이미지 이벤트로 사진의 크기를 조정할 수있는 간단한 AppleScript가 있습니다. 사진은 모든 축구 선수 들이며, 모두 "1.jpg", "4.jpg"등과 같이 번호가 지정됩니다. 내가 겪게되는 문제는 다른 디렉토리에서 플레이어의 여러 배치를 수행 할 때 스크립트가 동일한 파일 이름을 가지고 이전에 수행 된 다른 팀의 사진으로 사진을 덮어 쓰게 될 때입니다. 다시 말하지만,이 사진들은 모두 다른 디렉토리에 배치되었습니다. 최종 결과는 2 ~ 3 번 성공적으로 실행 한 후 플레이어의 형식이 변경된 사진이 혼란스러워집니다.이미지 이벤트 용 스크립트가 이전에 동일한 이름의 파일을 다시 포맷 한 파일을 덮어 쓰고 있습니다.

다음은 이미지 이벤트를 호출하는 스크립트입니다.

on open some_items 
    repeat with this_item in some_items 
     try 
      rescale_and_save(this_item) 
     end try 
    end repeat 
end open 


to rescale_and_save(this_item) 
    tell application "Image Events" 
     launch 
     set the target_width to 290 
     -- open the image file 
     set this_image to open this_item 

     set typ to this_image's file type 

     copy dimensions of this_image to {current_width, current_height} 
     if current_width is greater than current_height then 
      scale this_image to size target_width 
     else 
      -- figure out new height 
      -- y2 = (y1 * x2)/x1 
      set the new_height to (current_height * target_width)/current_width 
      scale this_image to size new_height 
     end if 

     tell application "Finder" to set new_item to ¬ 
      (container of this_item as string) & "" & (name of this_item) 
     save this_image in new_item as typ 

    end tell 
end rescale_and_save 

답변

2

이미지 이벤트에서 동일한 이름을 가진 여러 항목을 처리하는 버그가 발생했습니다. 나는 당신이 묘사 한 정확한 행동을 보지 못하고 있지만 비슷한 행동을보고 있습니다.

각 폴더를 처리 한 후에 이미지 이벤트를 종료하면됩니다. 그런 식으로 혼동하지 않을 것입니다. (당신은 어느 launch 필요하지 않습니다, 당신은 제목없는 문서 창을 제시하지 않고 열 수있는 비 배경 응용 프로그램을 원하는 경우 launch를 사용하는 유일한 이유입니다.)

덧붙여, 기존 이미지를 덮어 쓰려면 크기가 조정 된 버전에서는 save this_image 만 있으면됩니다. 이미지 이벤트는 문서를 열고 수정하고 저장하는 경우 다른 응용 프로그램과 매우 유사하게 동작합니다.

+0

감사합니다. –

관련 문제