Re: Combination
Re: Combination
- Subject: Re: Combination
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 28 Sep 2001 03:01:22 -0700
On 9/28/01 12:09 AM, "Bernard Azancot" <email@hidden> wrote:
>
>
I am trying to combine 2 Outlook express scripts:
>
>
The first one works perfectly. It performs bulk decoding on coded mail,
>
using the application "APICRYPT", and saving it to different folders.
>
It is widely inspired and adapted from Paul Berkovitz's "Messages to disk
>
v2" script.
>
>
The second one, renames each message from strings taken into it. It was
>
given here by Paul, too. Difficult to avoid Paul when you start Outlook
>
express or Entourage scripting ;-)
>
>
My purpose would be decrypting and then, rename each message, before saving
>
it.
>
To put it clearly, each one of the 2 scripts is working serarately fine. My
>
problem is to combine them.
Sorry I didn't get back to you earlier, Bernard. Partly because I didn't
know what you were talking about with "my" "Messages to disk v2" script. I
don't recall writing any such script. Now that you've sent it, it doesn't
look like mine at all. It must be someone else's (unless maybe I just
provided a bit of help to something you sent in.). Also, I've never heard of
APICRYPT.
1) First of all, I did not write "Messages to disk v2". For a start, I
never use the Finder for checking file names or incrementing numbers at the
end. (It's slow and can create problems when the script moves on before the
Finder has finished doing what it's doing, and the file you thought you had
created may not quite exist yet.) And there's some unneeded, redundant fluff
in there too that I would never include. Instead of
tell application "Finder"
repeat while exists fileName
I would do most of it outside the Finder, via
on GetValidFileName(folderPath, fileName) -- instead of CreatetheFile
set counter to 0
if (count fileName) is greater than or equal to 31 then set fileName
to (text 1 thru 28 of fileName)
set filePath to folderpath & fileName
set done to false
repeat until done
try
set theFile to alias filePath -- if doesn't error, file exists
already, continue
set counter to counter + 1 -- don't bother with counterstr
set fileName to fileName & " " & counter
set FilePath to folderPath & fileName
end try
set done to true -- alias filePath errored, doesn't exist quit
repeat
end repeat
return FilePath
end GetValidFileName
Note that it does NOT create any file, since there is nothing to put in the
file yet. It just gets a valid, unused file name for a file to be created in
the folder. By the way, if you expect more than 9 files with the same name,
the routine above will give an awful order: 1, 10 11, 12...19, 2, 20, 21,
etc. You should instead use
set counterStr to text -2 thru -1 of ("0" & counter)
set fileName to folderPath & counterStr
That will give you 01, 02, ...09, 10, 11, ...19, 20, 21, etc.
2) Do the second script "first", as a handler within the first script. I.e.
first extract the file name you want for each message. Since it seems you
want to do this in bulk, use the beginning of the first script to operate on
each message, and first get your (original) file name by
set fileName to ExtractFileName(theMessage)
Just put the whole second script into a handler, without setting theMsg to
item 1 of (get current messages). You can pass the message itself as a
parameter (but see below for what I think is a better method using message
Ids.).
to ExtractFileName(theMsg)
tell application "Outlook Express"
set theSubject to subject of theMsg
set theContent to content of theMsg
end tell
-- <rest of second script>
return FileName
end ExtractFileName
Another way to do this, which doesn't involve trying to pass an application
object (a message) as a parameter is: before going to the handler, in the
OE tell block:
tell app "Outlook Express"
-- <first part of script>
set messageID to ID of theMessage
end tell
set fileName to ExtractFileName(messageID)
Then the handler would just pass the ID (an integer):
to ExtractFileName(messageID)
tell application "Outlook Express"
set theMsg to message id messageID
set theSubject to subject of theMsg
set theContent to content of theMsg
end tell
-- <rest of second script>
return FileName
end ExtractFileName
That's what I'd prefer to do myself. Then, with that fileName returned, you
then do the
set fileName to GetValidFileName(folderPath, fileName)
as above.
Then create the file via
on SaveMessage(FilePath, theSource)
tell application "Finder"
set FileRefnum to (open for access file FilePath with write
permission) -- dossier Temporaire
write theSource to FileRefnum
close access FileRefnum
end tell
end SaveMessage
which will create the file for you, Finally you can give it a different
creator code if for some reason "TEXT" doesn't appeal to you. (Is this
really necessary?) You can do that in the Finder
tell app "Finder" to set creator type of alias FilePath to cType
as a final line of SaveMessage handler, if you had added it as a parameter
of course:
on SaveMessage(FilePath, theSource, cType)
--etc
(or it can be done by Akua Sweets's 'set catalog info' command).
HTH.
--
Paul Berkowitz
References: | |
| >Combination (From: Bernard Azancot <email@hidden>) |