Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.8: New Notes App Service System 10.8
I put together a simple Automator action that takes the selected text from any application and creates a new Note. This sort of thing should have been in the Services menu to begin with, but this powerful feature of OS X is often unsung and underused. Hope it helps.

Open Automator and create a new Service. Set the Service to receive selected text in any application from the drop down menus.

Drag Copy to Clipboard from the Utilities library into the workflow. Drag Run AppleScript from the Utilities library into the workflow.

Paste the below text in place of (* Your script goes here *):
tell application "Notes" to activate
tell application "System Events"
 click menu item "Notes" of ((process "Notes")'s (menu bar 1)'s ¬
  (menu bar item "Window")'s (menu "Window"))
 click menu item "New Note" of ((process "Notes")'s (menu bar 1)'s ¬
  (menu bar item "File")'s (menu "File"))
	keystroke "v" using {command down}
end tell
Save the Service with a name like New Note. Now when you right click on selected text you can find the New Note service in the Services contextual menu. When selected it creates a new note out of the selected text.

[crarko adds: I compiled the script and it seemed to work. I didn't test the Automator Service.]
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (9 votes cast)
 
[8,121 views]  

10.8: New Notes App Service | 18 comments | Create New Account
Click here to return to the '10.8: New Notes App Service' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.8: New Notes App Service
Authored by: the_webmaestro on Apr 12, '13 08:59:46AM
I get an error when I tested this outside of Automator:
The action “Run AppleScript” encountered an error.
If I run it from within Automator, I get a more useful error, indicating the following...
Syntax Error

System Events got an error: Access for assistive devices is disabled.
This gives the clue on how to fix this:
  1. Open System Preferences > System > Accessibility
  2. Check [x] Enable access for assistive devices
  3. Re-test
Your new service should now function as expected. Thanks!
---
Happy Dad


[ Reply to This | # ]
10.8: New Notes App Service
Authored by: petieg on Apr 12, '13 09:40:56AM

Looks like you need to have Notes running for this to work... I just duplicated the first line and it now works properly if you don't already have Notes running.


tell application "Notes" to activate
tell application "Notes" to activate
tell application "System Events" ... ...



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: thawk9455 on Apr 12, '13 10:37:23AM
Here's a slightly different version that doesn't overwrite your clipboard...

Open Automator and create a new Service. Set the Service to receive selected text in any application from the drop down menus.

Drag Run AppleScript from the Utilities library into the workflow.

Paste the below text in place of (* Your script goes here *):

set theInput to quoted form of (input as text)
set noteText to do shell script "echo " & theInput & " | /usr/bin/textutil -stdin -stdout -convert html"
	
tell application "Notes"
	tell account "iCloud"
		if not (exists folder "Notes") then make new folder with properties {name:"Notes"}
		tell folder "Notes"
			make new note with properties {body:noteText}
		end tell
	end tell
end tell



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: Beezlegrunk on Apr 12, '13 02:28:53PM

Followed your instructions, but it didn't work for me. The new service showed up in the Services menu, but nothing happened when I selected text and then invoked the service. If it helps to diagnose the issue, Notes was already running, and I'm using OSX 10.8.3.



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: Beezlegrunk on Apr 14, '13 12:39:22PM

I'm replying to my own post to issue a correction: It turns out the script does work, but because it (deliberately) doesn't steal focus from whatever app you're using when you run the service, you have no way of knowing it did so unless you check, which I obviously didn't do.

One other thing: It also calls every note created from selected text "New note", which can make it a little difficult to tell which note corresponds to which text. Is there any way to have it used the first couple of words in the new note, as Notes does when you type a note manually?

Thanks again for the script, and sorry I cried wolf about it previously ...



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: gcastaneda on Apr 12, '13 04:45:36PM

Unlike the original hint, this version works for me.



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: Sesquipedalian on Apr 13, '13 12:00:30AM
Much better than the original, since you avoid GUI scripting!

However, rather than hard-coding the account to use into the script, it would be better to set the script to always use whatever account the user has set as their default account. So, replace the line that says

tell account "iCloud"

with one that says

tell account id (do shell script "defaults read -app Notes DefaultAccount")

[ Reply to This | # ]
10.8: New Notes App Service
Authored by: Lri on Apr 13, '13 02:33:35AM

If the script doesn't work with rich text input, why do you need to convert the text to HTML? It makes the body use Times 12 instead of the default font.

defaults -app doesn't work with Notes (or a few other applications) for me for some reason. And I didn't even have a DefaultAccount key. It would be easier to just specify the account and folder in the script.

This also selects new notes:

on run {input, parameters}
	tell application "Notes"
		tell account 1 to tell folder "Notes"
			make new note with properties {body:input}
		end tell
		activate
	end tell
	tell application "System Events" to tell process "Notes"
		set selected of row 1 of table 1 of scroll area 1 of group 1 of splitter group 1 of window 1 to true
		set focused of group 1 of UI element 1 of scroll area 1 of group 2 of splitter group 1 of window 1 to true
	end tell
end run
Edited on Apr 13, '13 02:36:10AM by Lri


[ Reply to This | # ]
10.8: New Notes App Service
Authored by: thawk9455 on Apr 13, '13 07:13:16PM

By converting to HTML you maintain line breaks, indentation, etc...

Edited on Apr 13, '13 07:51:38PM by thawk9455



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: thawk9455 on Apr 13, '13 07:59:26PM
I took a little of each of the suggestions above. I didn't activate Notes since I might not want to leave the application I'm in. I did have a default account set so that code works for me. I also was able to get the HTML conversion to set the font size but the font portion doesn't seem to be working. I'd love to hear a way to fix that cleanly...

on run {input, parameters}
	set noteText to do shell script "echo " & quoted form of (input as text) & ¬
		" | /usr/bin/textutil -stdin -stdout -fontsize 15 -font \"Noteworthy Light\" -convert html"
	tell application "Notes"
		tell account id (do shell script "defaults read -app Notes DefaultAccount")
			if not (exists folder "Notes") then make new folder with properties {name:"Notes"}
			tell folder "Notes"
				make new note with properties {body:noteText}
			end tell
		end tell
	end tell
	tell application "System Events" to tell process "Notes"
		set selected of row 1 of table 1 of scroll area 1 of group 1 of splitter group 1 of window 1 to true
		set focused of group 1 of UI element 1 of scroll area 1 of group 2 of splitter group 1 of window 1 to true
	end tell
end run
Edited on Apr 13, '13 08:05:11PM by thawk9455


[ Reply to This | # ]
10.8: New Notes App Service
Authored by: Lri on Apr 14, '13 06:35:25AM

And apparently the body is always HTML, so you also need to escape characters like <. Just adding white-space:pre seems to preserve whitespace though.

on run {input, parameters}
	tell application "Notes"
		tell folder 1 of account 1
			make new note with properties {body:"<body style=white-space:pre>" & my amp(input) & "</body>"}
		end tell
		activate
	end tell
	tell application "System Events" to tell process "Notes"
		set selected of row 1 of table 1 of scroll area 1 of group 1 of splitter group 1 of window 1 to true
		set focused of group 1 of UI element 1 of scroll area 1 of group 2 of splitter group 1 of window 1 to true
	end tell
end run

on amp(input)
	my replace(input, "&", "&amp;")
	my replace(result, "<", "&lt;")
	my replace(result, ">", "&gt;")
end amp

on replace(input, x, y)
	set text item delimiters to x
	set ti to text items of input
	set text item delimiters to y
	ti as text
end replace

In the previous scripts you should use printf %s, <<<, or shopt -u xpg_echo; echo. echo interprets escape sequences by default in OS X's /bin/sh, so for example do shell script "echo " & quoted form of tab prints a literal tab.



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: TokyoDan on Apr 12, '13 03:44:27PM

"Drag Copy to Clipboard from the Utilities library into the workflow. Drag Run AppleScript from the Utilities library into the workflow. "

I have no idea what the above sentence means. How the hell do you drag copy something into the "workflow". And what is the "workflow"? ANd what do I drag copy from the Utilities Library?
And I never heard of "Drag Run". Please write your tips so that they make sense.



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: zoff on Apr 14, '13 12:28:28PM

Really?



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: cybernanga on Apr 14, '13 02:23:41PM

"Copy to Clipboard" and "Run AppleScript" are items that are in the Utilities Library in Automator.

You drag them to the workflow area, when creating an automator workflow.



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: dajaka on Apr 13, '13 11:14:35AM

You might want to check out the app PopClip.

It lets you open or manipulate selected text in numerous apps, including Notes, Stickies, Evernote, Notational Velocity and more.

I have no association with the app, except using it.



[ Reply to This | # ]
Notes Scripting Support
Authored by: mr. applescript on Apr 15, '13 12:56:28PM

The Notes scripting dictionary is described in detail with examples here:

http://macosxautomation.com/applescript/notes/index.html



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: ptr on Apr 16, '13 02:10:58AM

I don't get it working and now I can't remove the new service. How do I do that?



[ Reply to This | # ]
10.8: New Notes App Service
Authored by: thinkyhead on May 06, '13 01:55:05PM

Sorry, this is a bit offtopic. I was just wondering if anyone else has the same issue as me, where the "Find" command in Notes is always disabled. Is that just normal? Is there any way to enable it?

---
--
Scott Lahteine
"Thinkyhead"

The best place to hide a needle is among other needles.



[ Reply to This | # ]