This script *might* help. It has functions similar to what you are
trying. The list has helped me tweak this, so I consider it Public
Domain. Feel free to copy/cut/edit it as much as you want.
global theFolder
tell application "PowerMail"
set attachFolder to attachment folder
set theMessages to current messages
repeat with msg in theMessages
set msgStatus to status of msg
set attachList to attachments of msg
if (count items of attachList) > 0 then
set msgAttachFolder to ""
set msgAttachFolder to msgAttachFolder & (ID of msg)
tell application "Finder"
if not (exists folder (attachFolder &
msgAttachFolder as string))
then
set theFolder to (make new folder at
attachFolder with
properties {name:(msgAttachFolder as string)})
else
set theFolder to folder (attachFolder &
msgAttachFolder as string)
end if
end tell
repeat with attachIdx from (count items of attachList)
to 1 by -1
set attachFile to file of (item attachIdx of
attachList)
tell application "Finder"
set newAttachFile to (move attachFile
to theFolder without
replacing) as alias
end tell
delete attachment attachIdx of msg
make new attachment at msg with properties
{file:(newAttachFile
as alias)}
end repeat
end if
end repeat
end tell
On Jun 2, 2006, at 10:16 AM, George Henne wrote:
> (Wayne: I think I understand you, but the changed code does the
> same thing)
>
> Here's the latest code.
>
> tell application "PowerMail"
> set theMessages to current messages
> repeat with msg in theMessages
> -- put your code here to do something on each message msg
>
> if exists (attachments of msg) then
> set fileList to attachments of msg
> repeat with theFile in fileList -- this code does not
> handle
> multiple
> CSV attachements
> set fname to theFile's name
> if fname contains ".csv" then
> set myFile to theFile's file
> set theText to my readFile(myFile)
> end if
> end repeat
> else
> set theText to the content of msg & time sent of msg
> end if
> end repeat
> end tell
>
> -- now send the text to Hypercard
> set the clipboard to ((theText) as text)
> tell application "SuperCard 4.5"
> activate
> do script "go to card 1 of stack NSB Invoice SC"
> do script "send mouseUp to cd button CopyClipboard"
> do script "send mouseUp to cd button UpdateImport"
> end tell
> -- SuperCard will now generate the reply
>
> on readFile(theFile)
> read theFile
> end readFile
>
>
>> Try moving your tell statements.
>> Close the tell for PowerMail, then run your SuperCard, then open a
>> new
>> Tell statement for Powermail to create a new message. That should fix
>> the problem. It will also prevent PM having to wait for SuperCard
>> to finish.
>>
>> Wayne
>>
>> -----Original Message-----
>>> From: George Henne <[EMAIL PROTECTED]>
>>> Sent: Jun 2, 2006 9:34 AM
>>> To: Wayne Brissette <[EMAIL PROTECTED]>
>>> Subject: Re(2): Problem running AppleScript that creates email
>>>
>>> Wayne,
>>>
>>> That's very kind.
>>>
>>> I simplified the explanation a bit on the board. The AppleScript
>>> actually calls Supercard, which is sending the message to
>>> Powermail; but
>>> I think the principle is the same.
>>>
>>> tell application "PowerMail"
>>> set theMessages to current messages
>>> repeat with msg in theMessages
>>> -- put your code here to do something on each message msg
>>>
>>> if exists (attachments of msg) then
>>> set fileList to attachments of msg
>>> repeat with theFile in fileList -- this code does not
>>> handle
>>> multiple
>>> CSV attachements
>>> set fname to theFile's name
>>> if fname contains ".csv" then
>>> set myFile to theFile's file
>>> set theText to my readFile(myFile)
>>> end if
>>> end repeat
>>> else
>>> set theText to the content of msg & time sent of msg
>>> end if
>>>
>>> -- now send the text to Hypercard
>>> set the clipboard to ((theText) as text)
>>> tell application "SuperCard 4.5"
>>> activate
>>> do script "go to card 1 of stack NSB Invoice SC"
>>> do script "send mouseUp to cd button CopyClipboard"
>>> do script "send mouseUp to cd button UpdateImport"
>>> end tell
>>> -- SuperCard will now generate the reply
>>> end repeat
>>> end tell
>>>
>>> on readFile(theFile)
>>> read theFile
>>> end readFile
>>>
>>>
>>>
>>>> I'll be happy to take a look at it if you want.
>>>>
>>>> Wayne
>>>>
>>>> -----Original Message-----
>>>>> From: George Henne <[EMAIL PROTECTED]>
>>>>> Sent: Jun 2, 2006 9:05 AM
>>>>> To: PowerMail Discussions <[EMAIL PROTECTED]>
>>>>> Subject: Problem running AppleScript that creates email
>>>>>
>>>>> I have an AppleScript that runs as a result of a mail filter.
>>>>> One of the
>>>>> things it does is create a PowerMail message. The script runs
>>>>> fine by
>>>>> itself: the problem is that it hangs when it is called from
>>>>> PowerMail.
>>>>>
>>>>> From what I can determine, PowerMail starts the script and
>>>>> waits for it
>>>>> to finish. The script tries to add an email to PowerMail's
>>>>> inbox, but
>>>>> PowerMail is not accepting events.
>>>>>
>>>>> Can anyone think of a way around this? We need PowerMail to
>>>>> start the
>>>>> script, then stop waiting for it.
>>>>>
>>>>> George Henne
>>>>> NS BASIC Corporation
>>>>> http://www.nsbasic.com
>>>>>
>>>>>
>>>
>>>
>
>
>
>