OneNote — no automation

Rahul on twitter asked

My answer: sadly no. Currently OneNote does not have a script interface that I know of. I’ve asked them for one. If they’d at least support spotlight then one could create search links hook://search/… (which is a way to work around insufficiently scriptable apps); but in my trials anyway (and from what others are saying on the web), OneNote does not even support Spotlight…

It would be good for the Mac automation community to make our voices heard with the #OneNote team. Meanwhile, I can’t recommend OneNote for productivity on a Mac (and certainly not with Hook).

Hook does work with EagleFiler, DEVONthink, and Evernote, all of which are used by Mac automation enthusiasts.

There is a “Copy Link to Page” / “Copy Link to Section” menu item for notebooks that are shared on the web.
UI Scripting allows you to get the link, but:

  • it’s flaky and works maybe 50% of the time
  • AFAIK there is no way to get the actual name of the Page/Section being copied, so the MD link is going to have an ugly title
  • the link will only open the Page / Section in the web version of one note, not the app.

Here’s the (Franken)Script that I use:

set the clipboard to ""
tell application "System Events"
	tell process "Microsoft OneNote"
		click menu item "Copy Link to Page" of menu 1 of menu item "Pages" of menu 1 of menu bar item "Notebooks" of menu bar 1
	end tell
	repeat 100 times -- poll clipboard for ~2.5 seconds
		try
			if (the clipboard) is not equal to "" then
				exit repeat
			end if
		end try
		delay 0.05
	end repeat
	
end tell

set addr to (the clipboard as text)
set myTitle to «class ut16» of (the clipboard as record)
get "[" & myTitle & "](" & addr & ")"

I’ve use the structure of the “Agenda” script, with a UI line that I picked up using UI Browser. I’m sure some regex could get the title, but frankly there are so many problems with this integration that I don’ t feel like tackling string manipulation in AppleScript on top of everything else! If anybody has any ideas, feel free…

1 Like