2010-05-04 5 views
14

Mail (Snow Leopard)과 함께 사용하기 위해 AppleScript를 작성하여 이미지 첨부 파일을 폴더에 저장하려고합니다. AppleScript로의 주요 부분이다 : 나는 복사/붙여 넣기하면, 그러나Mail AppleScript 함수에 대해 "Can not continue"를 사용합니다.

Event wasnt handled by an Apple event handler.

: 오류 -1708가

error "Mail got an error: Can’t continue isImageFileName." number -1708

입니다

:

실행
property ImageExtensionList : {"jpg", "jpeg"} 
property PicturesFolder : path to pictures folder as text 
property SaveFolderName : "Fetched" 
property SaveFolder : PicturesFolder & SaveFolderName 

tell application "Mail" 
    set theMessages to the selection 
    repeat with theMessage in theMessages 
    repeat with theAttachment in every mail attachment of theMessage 
     set attachmentFileName to theAttachment's name 
     if isImageFileName(attachmentFileName) then 
     set attachmentPathName to SaveFolder & attachmentFileName 
     save theAttachment in getNonexistantFile(attachmentPathName) 
     end if   
    end repeat 
    end repeat 
end tell 

on isImageFileName(theFileName) 
    set dot to offset of "." in theFileName 
    if dot > 0 then 
    set theExtension to text (dot + 1) thru -1 of theFileName 
    return theExtension is in ImageExtensionList 
    end if 
    return false 
end isImageFileName 

, 나는 오류 다른 스크립트로 isImageFileName() 같은 :

property ImageExtensionList : {"jpg", "jpeg"} 

on isImageFileName(theFileName) 
    set dot to offset of "." in theFileName 
    if dot > 0 then 
    set theExtension to text (dot + 1) thru -1 of theFileName 
    return theExtension is in ImageExtensionList 
    end if 
    return false 
end isImageFileName 

if isImageFileName("foo.jpg") then 
    return true 
else 
    return false 
end if 

잘 작동합니다. 왜 Mail은이 문제에 대해 불평합니까?

답변

23

"my isImageFileName"을 시도해보십시오. Mail이 아니라 AppleScript의 단점입니다.

25

다소 다를 수 있지만 설명이 있습니다. tell application "whatever" 블록에있는 경우 모든 호출은 스크립트의 사전이 아닌 해당 응용 프로그램의 사전의 네임 스페이스에서 수행됩니다. 그렇기 때문에 AppleScript에 이름에 대한 스크립트를 되돌아 보도록 명시해야합니다. my라고 말하면 tell me이라고 말하면서, 스크립트가 함수를 찾을 곳을 지시합니다.

+0

즉, 네임 스페이스 및 범위 문제입니다. 우수한. –

+1

내가 applescript를 배우는 것을 계속하는 것에 따라 나는 어떤 점에서 희망을 품는다, 그런 물건은 과량의 시간을 잡는 것을 그만 둘 것이다 : 내가 다른 언어의 필적하는 기능을 위해 더 많은 선을 더 많이 쓸 필요가있는이 점에서 그것은 느낀다. –

관련 문제