代码之家  ›  专栏  ›  技术社区  ›  Paul J. Lucas

为applescript函数发送“can't continue”邮件

  •  17
  • Paul J. Lucas  · 技术社区  · 16 年前

    我正在尝试编写一个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
    

    运行时,我得到错误:

    错误“mail got an error:can_t continue 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
    

    它工作得很好。为什么邮件会抱怨这个?

    2 回复  |  直到 15 年前
        1
  •  24
  •   Nicholas Riley    16 年前

    尝试“我的isImageFileName”。这不是邮件,只是一个小程序脚本的怪癖。

        2
  •  30
  •   eykanal    15 年前

    这可能是一个怪癖,但它有一个解释。如果你在 tell application "whatever" 块,所有调用都在该应用程序字典的命名空间中进行,而不是在脚本字典中进行。因此,您必须明确地告诉applescript,以便在脚本中查找该名称。说 my 就像是说 tell me 指示脚本在何处查找函数。