I’m trying to write a script which will take any message with subject “note to self” and copy the text into a new sticky note. Now Mail can execute scripts as part of a rule, but I’m unsure on how to grab the message with that subject and then copy the text out. Just selecting it would work, as there is a command-option-y key for making a new sticky (in the Services menu). GUI scripting is cool and may be the only way. Any thoughts? (or scripts?)
This might work. It does require GUI scripting. Create the following rule in Mail:
–
If | any | of the following conditions are met:
Subject | is equal to | note to self
Run AppleScript – Choose this script
on perform_mail_action(info)
tell application "Mail"
set theMessages to |SelectedMessages| of info
repeat with thisMessage in theMessages
set myNote to content of thisMessage
my makeStickyNote(myNote)
end repeat
end tell
end perform_mail_action
on makeStickyNote(noteText)
set the clipboard to noteText
-- do sticky GUI stuff
tell application "Stickies" to activate
tell application "System Events"
tell application process "Stickies"
tell menu item 1 of menu 3 of menu bar 1 to click -- make new sticky
tell menu item 6 of menu 4 of menu bar 1 to click -- paste
end tell
end tell
end makeStickyNote
Tested successfully with Mac OS X 10.2.5.
This should get you started. I have little scripting experience with iCal so I’ll leave that for you or someone else to figure out (and it would be greatly appreciated if you share the final script here and/or at ScriptBuilders ).
on perform_mail_action(info)
tell application "Mail"
set theMessages to |SelectedMessages| of info
repeat with thisMessage in theMessages
set myToDo to content of thisMessage
my makeToDo(myToDo)
end repeat
end tell
end perform_mail_action
on makeToDo(ToDoContent)
tell application "iCal"
-- do whatever is needed to create new To Do
end tell
end makeToDo
You would create a rule similar to the one above (for the sticky note script).
Many thanks, I was getting pretty aggravated with it.
So I went searching. This set of scripts includes a script that will make a new To Do in iCal.
Below is a basic (not nearly as complete) script that will create a new To Do in calendar 1 (for me, calendar 1 is “Home”). The script sets the priority to 1 (Very Important) and the due date is set to 3 days from the current date.
tell application "iCal"
set newToDo to (make new todo at end of todos of calendar 1 with properties ¬
{summary:"Test", priority:1, due date:(current date) + (3 * days)})
end tell
With a little creativity, one could include the information for due date and priority in the Mail message and then use it to generate a complete To Do. I hope this helps.