Re: Auto-save OE 5 attachments
Re: Auto-save OE 5 attachments
- Subject: Re: Auto-save OE 5 attachments
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 25 Oct 2002 09:18:28 -0700
On 10/25/02 5:58 AM, "Steve Savery" <email@hidden> wrote:
>
Hello
>
>
I'm relatively new to AppleScript, although I have written a few simple
>
scripts for my own use.
>
>
I want to be able to get Outlook Express to automatically save all
>
attachments for each email received (as it is received) to a new folder
>
with the new folders name made up from elements of the email message
>
(ie Subject and Senders name). So far, I've not been able to get
>
anything to work. Below is my code for you to (laugh) look at.
The main thing is that you need to study the OE dictionary more carefully,
in particular making note of which objects the properties you want to set
belong to, and what type these properties are.
Can we assume that you know how to get the message for your handler to work
on? If not, this is how you'd get the message being filtered by a rule and
send it to the handler:
tell application "Outlook Express"
set MyMessage to item 1 of (get current messages)
processMail(MyMessage)
end tell
>
>
on processMail(MyMessage)
>
>
set disk_production to alias of "Production"
(* I don't understand this one. What's it mean? If you're referring to a
mounted disk, you need a colon, and no 'of':
set disk_production to alias "Production:"
If it _doesn't_ exist or isn't mounted, that line will error. So maybe what
you want is:
set disk_production_Path to "Production:"
and later you can use a try/error block with 'alias' to see if it exists.
Personally, I'd do all that in one place, later when you need it. *)
>
>
if attachment of MyMessage > 0 then
(* Whoa! We're not even in an OE tell block yet. What is 'attachment'
supposed to mean to AppleScript? And _in_ a tell block, there is no such
thing as 'attachment' of an existing message. Attachments are elements, not
properties, so they need to be itemized: attachment 1, attachment 2, etc. Or
else 'attachments' (aka 'every attachment'), which is what you want here, I
think. Then you have to _count_ them, to get the number of them. ('Count' is
an AppleScript event implemented in OE's Standard Suite, where you can find
it in the dictionary.) It is understandable that anyone could get confused
by OE's treatment of 'attachment', since you are able to treat 'attachment'
as if it were a property, not a group of elements, when making a new
message. So: *)
tell application "Outlook Express"
set theAttachments to attachments of theMessage
-- you'll need these again later, so set variable now
if (count theAttachments) > 0 then
-- or :
-- if theAttachments /= {} then -- /= means 'is not equal to', not
an empty list
-- [ > tell application "Outlook Express"] -- don't need this line now
>
set mySenderName to display name of MyMessage
(*Messages don't have display names. You won't find 'display name' as a
property of 'message' in the OE dictionary. 'display name' is a property of
the [confusing] 'address' class. And _sender_ of a message has the type
'address'. So first you have to gt the sender of the message, hen get _its_
display name: *)
set mySender to sender of MyMessage
set mySenderName to display name of mySender
>
set mySubject to subject of MyMessage
--OK!
>
set myDate to weekday of date sent of MyMessage & " " & day of date
>
sent of MyMessage as string
(* Instead of getting 'date sent of MyMessage twice, get it once and set a
variable to it, then reset the variable to the string bits you need:
set myDate to date sent of MyMessage
set myDate to (weekday of myDate & " " & day of myDate)
-- 'day' will be coerced to string by the left side of the
concatenation
>
if length of (mySenderName & " " & mySubject & " Sent at " & myDate)
>
< 30 then
>
set new_folder_name to mySenderName & " " & mySubject & " Sent at "
>
& myDate
>
else
>
set new_folder_name to mySenderName & " " & myDate
>
end if
(* all that's OK but what if length of the shorter version is still > 30?
You need a routine to deal with that. And what if the folder name is already
taken? *)
>
--set create_location to "Production:Sales Email Attachements"
>
--set stored_location to create_location & ":" & new_folder_name
(* Why are these commented out? If you use the colon earlier, remove it
here. *)
>
end tell
>
>
tell application "Finder"
>
(*if disk_production exists then
>
--do nothing
>
else
>
mount volume "afp://193.115.84.20/production/" --without message
>
end if
>
if exists stored_location then
>
delete stored_location
>
end if*)
(*Some of that does not need to be in the Finder. I haven't used 'mount
volume' so I'm not sure you've got the right syntax (I believe there was a
bug with certain versions of AS), but I'll assume it's OK. And do you
_really_ want to delete previous folders of that name with everything in
them too? OK, This will do what you want: *)
try
get alias "Production:"
on error
mount volume "afp://193.115.84.20/production/"
end try
>
make new folder at desktop of startup disk with properties
>
{name:new_folder_name}
>
end tell
(* Whoa! Do you want this folder made on the desktop of the startup disk, or
on the mounted "Production" disk?? All this part is extremely confusing. I
think you'd better first say where you want this folder made. And you should
put all this Finder stuff at the beginning of the script, before the OE
part. Also, there's only one desktop. It will use your startup disk. Let's
just try one version:
set create_location to "Production:Sales Email Attachements:" -- note
colon, also do you really spell it with that extra "e" in the middle?
set stored_location to create_location & new_folder_name & ":"
tell application "Finder"
if not exists folder create_location then
make new folder at disk "Production:" with properties {name:
"Sales Email Attachements"}
end if
if exists folder stored_location then
delete folder stored_location --??? really?
update folder create_location
end if
make new folder at folder create_location with properties
{name:new_folder_name}
end tell
>
>
tell application "Outlook Express"
>
save (attachments from MyMessage to stored_location)
(* You don't save 'to', you save 'in': see 'save' in the OE dictionary. And
you don't save attachments 'from' anything. You can do it this way,
recalling that you already set 'theAttachments' to the message's
attachments. You need a repeat loop to save each attachment separately,
AFAIK, you can't save lists of attachments: *)
tell application "Outlook Express"
repeat with theAttachment in theAttachments
save theAttachment in stored_location
end repeat
end tell
(*Since stored_location now ends in a colon, denoting it's a folder, not a
file, you can save in it although that's not really documented. 'save in'
is really meant to save in a file specification path for each attachment,
but since you don't need to keep track of each one by setting a variable to
each saved file, this way works OK. *)
>
end tell
>
>
end if
>
end processMail
>
>
If anybody can help I'd really appreciate it. I'm a quick learner and
>
have recently bought the book "AppleScript for Applications" by Ethan
>
Wilde.
>
Hope that helps.
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.