SOLVED! -- Saving Attachment from Mail.app
SOLVED! -- Saving Attachment from Mail.app
- Subject: SOLVED! -- Saving Attachment from Mail.app
- From: John Delacour <email@hidden>
- Date: Fri, 21 Mar 2003 10:36:48 +0000
- Mac-eudora-version: 6.0a11
At 9:38 am +0000 21/3/03, John Delacour wrote:
At 12:18 am -0800 21/3/03, Alan Kimelman wrote:
Although I have used the following script, successfully, I find that
writing the source of a mail message to a file significantly slows the
process. This script works, but is slow.
I've had a look at the script and dicover that what is slowing
things down is the changing of the line endings. Writing to the
file takes only 1/20 second.
I'll try to find out why the line endings matter, because I don't
think they ought to. Watch this space.
OK I've discovered what the problem is. The source of the Mail.app
message is Unicode, in other words it's full of invisible bytes or
"gremlins". The problem Stuffit Expander had was not with the line
endings but with all the gremlins.
Doing the painfully slow process with text item delimiters cured the
problem, but not because the line endings were changed; rather
because the Unicode text was in the process converted to a string.
Before I realised this I tried the (*commented*) perl routine in the
script below to change the line endings, and this was miles faster
but did not solve the problem of the gremlins.
I then had the lucky hunch to take a look at s in Script Editor's
result pane and saw what the problem was (which is not evident in
BBEdit until you show invisibles). There was a "space" (in fact a
\000) before each character of s.
Finally I scrapped all the unnecessary line-ending routinews and
simply added "as string" to the write command. As you will see, this
does the trick.
tell application "StuffIt Expander" to run
set _ticks to {}
set t to (the ticks)
set f to "" & (path to "desk") & "temp.txt"
set fPosix to POSIX path of f
--return fPosix
tell application "Mail"
selection
first item of result
set s to source of result
end tell
set end of _ticks to {"Get source: " & ((the ticks) - t)}
try
close access file f
end try
open for access file f with write permission
set eof file f to 0
-- write with UNIX line endings
write s to file f as string
close access file f
-- change line ending to cr
(*
do shell script "perl -e'
open F, qq~" & fPosix & "~ or die $! ;
for (<F>) {push @lines, $_}
open F, qq~>" & fPosix & "~ or die $! ;
for (@lines) {chomp, print F qq~$_\\015~}
'"
*)
set end of _ticks to {"Write file: " & ((the ticks) - t)}
--return read alias f
tell application "StuffIt Expander"
Expand {alias f} Destination (path to desktop)
end tell
set end of _ticks to {"Expand file: " & ((the ticks) - t)}
_ticks
--> {{"Get source: 2"}, {"Write file: 11"}, {"Expand file: 38"}}
_______________________________________________
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.