2010-05-04 12 views
14

के लिए मेल "जारी नहीं रख सकता" मेल मैं संदेशों के संदेश अनुलग्नकों को सहेजने के लिए मेल (हिम तेंदुए पर) के उपयोग के लिए एक ऐप्पलस्क्रिप्ट लिखने की कोशिश कर रहा हूं। AppleScript का मुख्य हिस्सा है:ऐप्पलस्क्रिप्ट फ़ंक्शन

error "Mail got an error: Can’t continue isImageFileName." number -1708

जहां त्रुटि -1708 है:

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 

जब चलाने के लिए, मैं त्रुटि मिलती है

Event wasnt handled by an Apple event handler.

हालांकि, अगर मैं कॉपी/पेस्ट

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 
: की तरह एक और स्क्रिप्ट में

यह ठीक काम करता है। मेल इस बारे में शिकायत क्यों करता है?

उत्तर

23

"मेरा isImageFileName" आज़माएं। यह मेल नहीं है, सिर्फ ऐप्पलस्क्रिप्ट का एक quirk।

25

यह एक quirk हो सकता है, लेकिन यह एक स्पष्टीकरण है। यदि आप tell application "whatever" ब्लॉक में हैं, तो सभी कॉल उस एप्लिकेशन के शब्दकोश के नामस्थान में बनाई गई हैं, न कि आपकी स्क्रिप्ट का शब्दकोश। इसके कारण, आपको ऐप्पलस्क्रिप्ट को नाम के लिए अपनी स्क्रिप्ट में वापस देखने के लिए स्पष्टीकरण देना होगा। my कहकर tell me कह रहा है, स्क्रिप्ट को निर्देश देना है कि फ़ंक्शन को देखने के लिए कहां है।

+0

दूसरे शब्दों में यह एक नामस्थान और दायरा मुद्दा है। अति उत्कृष्ट। –

+1

मुझे उम्मीद है कि मैं कुछ समय पर एप्पलस्क्रिप्ट सीख रहा हूं, ऐसी चीजें असमान समय लेने से बाहर निकल जाएंगी :) इस बिंदु पर ऐसा लगता है कि मुझे अन्य भाषाओं की तुलनीय कार्यक्षमता के लिए एएस में कई और पंक्तियां लिखनी हैं। –

संबंधित मुद्दे