(*

Create Yojimbo Note From Mailsmith Messages

John Gruber

29 May 2007


This script creates a new Yojimbo note for each selected message in

Mailsmith, with the note title set to the message subject.


By default, the content of each Yojimbo note is the entire body of

the email message. If only one message is selected in Mailsmith,

however, you can select a portion of the message body before running

the script, and only the selected text will be sent to Yojimbo.


*)


tell application "Mailsmith"

-- Get the current message or multiple selected messages

set retry to false

try

set msg_list to get selection as list

set m to item 1 of msg_list

if class of m is not message then set retry to true

on error

set retry to true

end try

if retry then

set retry to false

try

set msg_list to message of window 1 as list

on error

set retry to true

end try

end if

if retry then set msg_list to {}

-- Get the selected text, if any, to use as the note body

set _selected_text to ""

if class of selection of window 1 is character then

set _selected_text to selection of window 1 as string

end if

-- Process each message

repeat with i from 1 to count items of msg_list

try

set _msg to item i of msg_list

set _subject to subject of _msg as string

set _date to time received of _msg as string

set _from_name to display name of originator of _msg

set _from_address to address string of originator of _msg

set _to to primary recipient of _msg

if _selected_text is "" then

set _body to contents of _msg as text

else

set _body to _selected_text

end if

set note_text to "From:" & tab & _from_name & ¬

" <" & _from_address & ">" & return ¬

& "To:" & tab & tab & _to & return ¬

& "Date:" & tab & _date & return ¬

& "Subject:" & tab & _subject & return & return ¬

& _body

tell application "Yojimbo"

make new note item with properties ¬

{name:_subject, contents:note_text}

end tell

on error msg

display dialog msg

end try

end repeat

end tell


tell application "Yojimbo" to activate