NotePlan integration scripts

Hi!

I made some scripts in an attempt to integrate Noteplan. I’m almost there - not getting the items linked back properly. Maybe somebody can see what I’m getting wrong (I cannibalised the agenda scripts to make these).

Get Name

set the clipboard to “”
tell application id “co.noteplan.NotePlan” to activate
tell application “System Events”
key code 126 using {command down}
key code 124
key code 124
key code 124 using {shift down}
keystroke “c” using {command down}
delay 0.5
get (the clipboard as text)

Get Address

set the clipboard to “”
tell application id “co.noteplan.NotePlan” to activate
tell application “System Events” to keystroke “u” using {command down}
delay 0.5
get (the clipboard as text)

New Document

tell application id “co.noteplan.NotePlan”
reopen
activate
end tell
tell application “System Events”
tell process “Noteplan”
keystroke “n” using {command down}
delay 0.5
set the clipboard to “$title”
delay 0.3
keystroke “v” using {command down}
delay 0.3
keystroke “u” using {command down}
delay 0.5
get (the clipboard as text)
end tell
end tell

Thanks for this script @Jan_Salomonsson ! We will have a look. And I’ve sent an email to NotePlan requesting AppleScript or JavaScript support in their app, and asking them to give me a call to discuss if need be.

1 Like

I’ve had an exchange with the developer of NotePlan. They support xcallback URL. we may be able to use that. We will have a look.

NotePlan looks like a great app. I’m looking forward to its integration with Hook.

1 Like

Hi there, I’m the developer of NotePlan. Thought I just jump in and help wherever I can. Besides x-callback-url (see https://noteplan.co/faq/General/X-Callback-Url%20Scheme/), NotePlan saves it’s files as human readable text files in the iCloud Drive folder. So technically you have access to the database at all times. Just open and read the files or write into them.

Let me know what you want to achieve with the script, maybe I can help.

2 Likes

Yeah I think NotePlan and Hook will combine really well

1 Like

Thanks! I think the scripts will need a little work to get the link on both ends. These are my first posts here and I don’t know how the scripts have come about before, but drop me a line if I can help somehow.

I put together some scripts to integrate Hook with NotePlan

They work with both notes and dates.

Get Name

set the clipboard to ""
tell application "System Events" to tell process "NotePlan"
	try
		click menu item "Copy Link to Note" of menu "Note" of menu bar 1
		delay 0.1
		set noteTitle to the clipboard
		set noteTitle to text 3 thru -3 of noteTitle
		get noteTitle
	on error
		click menu item "Copy Link to Date" of menu "Note" of menu bar 1
		delay 0.1
		set noteTitle to the clipboard
		set noteTitle to text 3 thru -3 of noteTitle
		get my formatDate(noteTitle) as string
	end try
end tell

on formatDate(d)
	tell date d
		get its month & " " & its day & ", " & its year
	end tell
end formatDate

Get Address

set the clipboard to ""
tell application "System Events" to tell process "NotePlan"
	try
		click menu item "Copy Link to Note" of menu "Note" of menu bar 1
		delay 0.1
		set noteTitle to the clipboard
		set noteTitle to text 3 thru -3 of noteTitle
		set escapedTitle to do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of noteTitle
		get "noteplan://x-callback-url/openNote?noteTitle=" & escapedTitle
	on error
		click menu item "Copy Link to Date" of menu "Note" of menu bar 1
		delay 0.1
		set noteTitle to the clipboard
		set noteTitle to text 3 thru -3 of noteTitle
		set dateString to my formatDateAddr(noteTitle)
		get "noteplan://x-callback-url/openNote?noteDate=" & dateString
	end try
end tell

on formatDateAddr(d)
	set {year:y, month:m, day:d} to date d
	return (y * 10000 + m * 100 + d)
end formatDateAddr

URLs in NotePlan are based on the title of the note, which is just the first line of the note. If you change the title of a note, you will change the URL and break any links with that note, but that’s the case with all links within NotePlan too.

Thanks! Vast improvement over what I had. Now we just need an add new :).

1 Like

Your New script is working for me if I increase the final delay (before get (the clipboard as text)) to 1 full second.

repeat 3 times
  if the clipboard as text is ”” then
      delay 0.3
  else
      get the clipboard as text
      exit repeat
  end if
end repeat