Title: Re: New Note from Selected Text (trying to write)
On or near 1/29/2001 6:25 PM, Chris Stearns at [EMAIL PROTECTED] observed:
> Here's what I wound up with. It doesn't work. I get the second error dialog
> (”There was an error saving the selection “). I had to cut the link part out
> completely or the script wouldn’t compile. Can anyone tell me where I’m going
> wrong?
>
There were several problems. I've patched them, without trying to rewrite the script entirely for optimum efficiency. It works now:
-- Script from a message sent by Chris Stearns
-- on Monday, January 29, 2001 6:25:59 PM
tell application "Microsoft Entourage"
activate
(* Comments in these blocks can be deleted. You needed to obtain the current message so you can reference it later. “current messages” returns a list, even for a single message; you need just the first item in the list. *)
set msgs to the current messages
set aMsg to item 1 of msgs
set theText to ""
try
set theText to the selection
-- trigger error if no text
(* Here, you had an empty if/end if that did nothing. I’ve put in an error message and a return to exit the script. *)
if theText is "" then
display dialog ¬
"This script works on text selected in a message." buttons {"OK"}
return
end if
on error
display dialog ¬
"This script works on text selected in a message." buttons {"OK"}
(* Added “return” to exit the script if nothing is selected. This and the above could probably be combined somehow if you were concerned about duplicating code, but in a script this short it hardly matters. *)
return
end try
try
if theText is not "" then
-- get the information from the message, and store it in variables
(* You were referring to theText, which is just a text variable. You needed to refer to the message to get the subject and category. *)
set theName to subject of aMsg
set theCategory to category of aMsg
(* You were setting a variable to “the content of theText” which is pretty meaningless; just use “theText” in the following statement when you make the note. *)
-- create a new note with the information from the message
set newNote to make new note with properties {name:theName, category:theCategory, content:theText}
--Optional, uncomment next line if you want the note to be open
open newNote
end if
(* Your error routine displayed the same message no matter what error occurred. The first thing I did was to change the error routine as below, so that the <actual error> gets displayed. To see what I mean, try changing one of the above lines, say “set theCategory”, to “set theCategory to category of theText” as you originally had, and see what the error message looks like. Lots more informative! If you simply put a variable name like “theErr” after “on error”, it gets filled in with the text of the actual error code. You can then display it in the next statement. *)
on error theErr
display dialog theErr buttons {"OK"}
end try
end tell
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>
- New Note from Selected Text (trying to write) Chris Stearns
- Re: New Note from Selected Text (trying to writ... Allen Watson
- Re: New Note from Selected Text (trying to writ... Chris Stearns
- Re: New Note from Selected Text (trying to ... Allen Watson
- Re: New Note from Selected Text (trying to writ... Chris Stearns
- Re: New Note from Selected Text (trying to ... Christian M. M. Brady
- Re: New Note from Selected Text (trying... Paul Berkowitz
- Re: New Note from Selected Text (tr... Christian M. M. Brady
- Re: New Note from Selected Text (tr... Christian M. M. Brady
- Re: New Note from Selected Text (trying... Paul Berkowitz
- Re: New Note from Selected Text (tr... Christian M. M. Brady
