Tôi đang cố gắng viết một AppleScript để sử dụng với Mail (trên Snow Leopard) để lưu các tệp đính kèm hình ảnh của thư vào một thư mục. Phần chính của AppleScript là:Thư "Không thể tiếp tục" cho chức năng 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
Khi chạy, tôi nhận được lỗi:
error "Mail got an error: Can’t continue isImageFileName." number -1708
nơi lỗi -1708 là:
Event wasnt handled by an Apple event handler.
Tuy nhiên, nếu tôi sao chép/dán số isImageFileName()
vào một tập lệnh khác như:
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
nó hoạt động tốt. Tại sao Mail phàn nàn về điều này?
Nói cách khác, đó là vấn đề về không gian tên và phạm vi. Xuất sắc. –
Tôi hy vọng tại một số điểm như tôi tiếp tục học tập bản thảo, những thứ như vậy sẽ bỏ thời gian không cân xứng :) Tại thời điểm này, tôi cảm thấy mình phải viết nhiều dòng AS hơn để có thể so sánh được chức năng của các ngôn ngữ khác. –