create a new note in mail.app

Is it possible to create a new note in mail.app and set its contents to some text? If not with applescript, can it be done in cocoa with obj-c?

I didn’t see anything in mail’s dictionary about it so the only way I can think is to use keystrokes. Is there a better way?

set noteTitle to "A New Note"
set noteText to "Some text to enter"
set fullNote to noteTitle & return & return & noteText
set d to 0.5 -- a delay time in seconds

set the clipboard to fullNote

tell application "Mail" to activate
tell application "System Events"
	delay d
	keystroke "n" using {command down, control down} -- create new note
	delay d
	keystroke "v" using command down -- paste in the clipboard
	delay d
	keystroke "w" using command down -- close the note window
	delay d
	keystroke "h" using command down -- hide mail
end tell

Applications like Anxiety and Bento use Sync Services to share data with iCal and Addressbook. Apple also supports Mail notes with Sync Services, but I’m not aware of any sample code that might get you to a finished product within a day’s work.

If you can live with UI scripting, I’d stick to that and file a bug report on the missing AppleScript implementation in Mail.

Relevant links:

Sync Services
http://developer.apple.com/documentation/Cocoa/Conceptual/SyncServices/SyncServices.html

Mail Notes Schema Reference
http://developer.apple.com/documentation/AppleApplications/Reference/SyncServicesSchemaRef/Articles/Notes.html

Does this help?

set theBody to "abc"
set theSubject to "XYZ"
set theTarget to "xxx@2.com"

tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}

    tell newMessage
        make new to recipient at end of to recipients with properties {address:theTarget}
        set sender to "123@mail.com"
    end tell

    send newMessage
end tell

No. That’s how to create an email, not a note… thanks for the thoughts though.

Thanks for the idea. I’m definitely going to look into that more. This idea is actually for a coca application I wrote so if I can figure out sync services then it would fit right into my app. The gui scripting technique I showed above wouldn’t work for my cocoa app so I need something better. I thought applescript would be the way to go but obviously there’s nothing native to handle Mail notes.

As such if anyone knows of any tutorials about using sync services please let me know. Or if you have any other applescript ideas.