2011-10-08 6 views
1

다음 applescript가 있습니다. 나는 그것이 IM을받을 때 ichat에서 달리도록 설정했습니다. 새 메시지가 끊임없이 알려줍니다.AppleScript에서 이미지가 비어 있는지 어떻게 테스트 할 수 있습니까?

내 친구에게 이미지가 연결되어 있지 않으면 오류가 발생합니다. 그래서 notify_growl에 if 문을 추가하려고합니다. 여기서 theImage가 비어 있거나 null이든, 무엇이든간에 이미지를 거칠게 만듭니다. 빈은 "msng"

답변

1

테스트, 널/정의되지 않은 값의 애플 스크립트의 아날로그. 대신 기본 이미지가 있다면

on notify_growl(theName, theTitle, theDescription, theImage) 
    tell application "Growl" 
     if theImage is missing value then 
      notify with name theName title theTitle description theDescription ¬ 
       application name "iChat" 
     else 
      notify with name theName title theTitle description theDescription ¬ 
       application name "iChat" image theImage 
     end if 
    end tell 
end notify_growl 

, 당신은 기본 이미지의

on notify_growl(theName, theTitle, theDescription, theImage) 
    tell application "Growl" 
     if theImage is missing value then set theImage to defaultImage 
     notify with name theName title theTitle description theDescription ¬ 
      application name "iChat" image theImage 
    end tell 
end notify_growl 

을 쓸 수있다 : 당신은 그냥 이미지를 생략하려는 경우 귀하의 경우, 그것은 다음과 같을 것

set defaultImageFile to open for access POSIX file "/some/file/path" 
set defaultImage to read defaultImageFile as "JPEG" 
close defaultImageFile 

가있을 수있는 쉬운 방법을하지만,이 당신에게 이미지를 얻을 것이다, 당신이 뭔가를 할 수 있습니다. 그러나, 귀하의 경우에는 효과가 없을만큼 느립니다.

1

이 시도라는 대화 상자를 표시 표시 대화 theImage;) missing value에 대한

on notify_growl(theName, theTitle, theDescription, theImage) 
    tell application "Growl" 
     try 
      notify with name theName title theTitle description theDescription application name "iChat" image theImage 
     on error 
      notify with name theName title theTitle description theDescription application name "iChat" 
     end try 
    end tell 
end notify_growl 
+0

+1 답변이 해결책이기 때문에 나는 직접 질문에 대답했기 때문에 @antal에게 최선의 답을주었습니다. – finiteloop

관련 문제