Почта "Не удается продолжить" для функции AppleScript - PullRequest
17 голосов
/ 04 мая 2010

Я пытаюсь написать 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

При запуске выдается ошибка:

error "Почта получила ошибку: не могу продолжить 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

работает нормально. Почему Mail жалуется на это?

Ответы [ 2 ]

30 голосов
/ 31 января 2011

Это может быть причудой, но у нее есть объяснение. Если вы находитесь в блоке tell application "whatever", все вызовы выполняются в пространстве имен словаря этого приложения, а не словаря вашего скрипта. Из-за этого вы должны подробно объяснить AppleScript, чтобы заглянуть в ваш скрипт для имени. Сказать my все равно что сказать tell me, указав сценарию, где искать функцию.

25 голосов
/ 04 мая 2010

Попробуйте "my isImageFileName". Это не Почта, просто причудливый AppleScript.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...