邮件"无法继续"AppleScript功能

Pau*_*cas 17 email applescript

我正在尝试编写AppleScript以与Mail(在Snow Leopard上)一起使用,以将邮件的图像附件保存到文件夹中.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
Run Code Online (Sandbox Code Playgroud)

运行时,我收到错误:

错误"邮件收到错误:无法继续isImageFileName." 数字-1708

其中错误-1708是:

事件没有由Apple事件处理程序处理.

但是,如果我将其复制/粘贴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
Run Code Online (Sandbox Code Playgroud)

它工作正常.Mail为什么抱怨这个?

小智 30

这可能是一个怪癖,但它有一个解释.如果你在一个tell application "whatever"块中,所有调用都在该应用程序的字典的名称空间中进行,而不是在脚本的字典中.因此,您必须明确告诉AppleScript回顾您的脚本以获取名称.说my就像说tell me,指示脚本在哪里寻找功能.

  • 我希望在某些时候,随着我不断学习AppleScript,这样的事情将会停止不成比例的时间:)在这一点上,感觉我必须在AS中编写更多的行以获得其他语言的可比功能. (2认同)

Nic*_*ley 26

试试"我的isImageFileName".这不是Mail,只是AppleScript的一个怪癖.