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

1 Like

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.

2 Likes

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.

3 Likes

Yeah I think NotePlan and Hook will combine really well

2 Likes

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

I’ve been using the following script to create new notes, but I get duplicate entries… removing any lines gets me the Hook URL error…

tell application id “co.noteplan.NotePlan”
reopen
activate
end tell
tell application “System Events” to tell process “NotePlan 2”
click menu item “New Note” of menu “File” of menu bar 1
delay 0.3
set the clipboard to “$title”
click menu item “Paste” of menu “Edit” of menu bar 1
delay 0.3
try
click menu item “Copy Link to Note” of menu “Note” of menu bar 1
delay 0.3
set notelink to the clipboard
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
end try
end tell

Welcome to the Hook Productivity Forum, @brokosz . And thanks for sharing. We’ll have a look at these scripts. @EduardMe , the NotePlan developer, might also have an idea.

Thanks Luc. For what it’s worth, I changed the bottom lines of the script to the following (longer delay, get the variable for the URL) and now it’s hit or miss about creating duplicates.

	try
		click menu item "Copy Link to Note" of menu "Note" of menu bar 1
		delay 0.5
		set notelink to the clipboard
		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
		set noteURL to "noteplan://x-callback-url/openNote?noteTitle=" & escapedTitle
		get noteURL
	end try
end tell
1 Like

Hi @brokosz, you want to create a new note and copy the url? You could also create a new file in the iCloud Drive folder?

Talked with @LucB already to add a command to create a new note. Will work on that.

Hi Eduard, :slightly_smiling_face:

Yes, using Hook’s New Item function with the script above to put a new note with an automatic Hook link in my iCloud Drive NotePlan folder. The script works, but somewhere near the end of the execution the current note loses focus and a second identical note is created as well. I’m wondering if its a timing issue where the new note hasn’t been saved yet and when the link to the note is called it creates a new one? I’m not sure.

thanks as always,
Brad