Re: Soft returns in string variable?
Re: Soft returns in string variable?
- Subject: Re: Soft returns in string variable?
- From: Graff <email@hidden>
- Date: Thu, 05 Feb 2004 00:21:41 -0500
I tried a little experiment and I wasn't able to duplicate what you are
seeing. If I run this script I only find Unix-style line endings:
------------
tell application "Mail"
set myMessage to selection
set myParseText to (content of item 1 of myMessage) as string
end tell
set thirteenFound to false
set theIndex to 0
repeat with theChar in every character of myParseText
if ((ASCII number theChar) = 10) then
if thirteenFound then
display dialog "Windows-style" & return & "At: " & theIndex
else
display dialog "Unix-style" & return & "At: " & theIndex
end if
else
if thirteenFound then
display dialog "Mac-style" & return & "At: " & theIndex
end if
end if
set thirteenFound to false
if ((ASCII number theChar) = 13) then
set thirteenFound to true
end if
set theIndex to theIndex + 1
end repeat
------------
For every single message that I selected and then ran this script, I
only saw Unix-style line endings. The only exception to this was for
html-encoded emails which I wasn't able to get any content on at all.
The only difference I was able to see was that if I changed this line:
set myParseText to (content of item 1 of myMessage) as string
to this:
set myParseText to (content of item 1 of myMessage) as text
With "as string" I got ASCII text, with "as text" I got Unicode text.
If I didn't use any coercion I got the same as using "as text".
You can see what line endings you have in a Mail message by opening the
message, pressing option-command-u, and then control-clicking on the
message body and selecting "Show Control Characters" from the
contextual menu. Unix-style endings will be "\n", Mac-style will be
"\r", and Windows-style will be "\r\n".
For some reason your messages are coming up as Windows-style, but I
don't think they should be. In any event you can make sure that all
line endings are converted to Unix-style with these three lines:
------------
set AppleScript's text item delimiters to ASCII character 10
display dialog (every paragraph of (content of myMsg)) as text
set AppleScript's text item delimiters to ""
------------
- Ken
On Feb 4, 2004, at 7:13 AM, dave dowling wrote:
I'm doing some scripting with Apple Mail. If I manually copy all the
text from the body of an email, I can set a variable to the clipboard
like this:
[do manual copy]
set myParseText to the clipboard
etc...
and my script works fine. However, if I have AS set a variable with
the content of the email message like this:
set myParseText to (content of myMsg)
or this:
set myParseText to (content of myMsg) as string
or even this:
set the clipboard to (content of myMsg) as string
set myParseText to the clipboard
I get non-ASCII characters in my resulting string. When I copy the
unwanted characters into BBEdit and choose to show invisibles, they
show up as carriage returns. In FileMaker Pro, which is the end point
for my text variable, I get little squares instead of legible
characters. I know I can zap gremlins in BBEdit to get rid of the
unwanted characters, but I'm hoping there's a way to strip them in AS
alone. I really don't care about adding any other applications to my
script.
Any idea why a manual copy to the clipboard would be different from an
AS copy to the clipboard? More important, any idea how I can set a
variable and strip out the non-ASCII characters?
Thanks.
Dave Dowling
http://www.davedowling.com
Free at last! How I found peace with God:
http://www.davedowling.com/peace.htm
_______________________________________________
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.
_______________________________________________
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.