我試圖寫一個AppleScript與郵件(雪豹)一起使用以將圖像附件的郵件保存到文件夾。該AppleScript的主要部分是:郵件「無法繼續」的AppleScript功能
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
跑的時候,我得到的錯誤:
error "Mail got an error: Can’t continue isImageFileName." number -1708
其中錯誤-1708是:
Event wasnt handled by an Apple event handler.
但是,如果我複製/粘貼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會抱怨?
換句話說,它是一個命名空間和範圍問題。優秀。 – 2013-02-06 21:57:48
我希望在某些時候,隨着我不斷學習applescript,這樣的事情將不再需要不成比例的時間:) 在這一點上,感覺就像我必須在AS中編寫更多的行,用於其他語言的可比較的功能。 – 2016-08-14 13:31:12