# NotePlan integration scripts

**URL:** <https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527>\
**Category:** Share Hookmark automation\
**Created:** [July 10, 2019, 3:03pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527 "2019-07-10T15:03:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Salomonsson](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jan_salomonsson/32/181_2.png) [@Jan\_Salomonsson](https://discourse.hookproductivity.com/u/Jan_Salomonsson)\
**Post date:** [July 10, 2019, 3:03pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/1 "2019-07-10T15:03:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [July 10, 2019, 7:34pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/2 "2019-07-10T19:34:11Z")

</div>

> [@Jan\_Salomonsson](#):
>
> Noteplan

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.

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [July 10, 2019, 8:33pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/3 "2019-07-10T20:33:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EduardMe](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@EduardMe](https://discourse.hookproductivity.com/u/EduardMe)\
**Post date:** [July 11, 2019, 12:30am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/4 "2019-07-11T00:30:15Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Jan\_Salomonsson](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jan_salomonsson/32/181_2.png) [@Jan\_Salomonsson](https://discourse.hookproductivity.com/u/Jan_Salomonsson)\
**Post date:** [July 11, 2019, 8:11am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/5 "2019-07-11T08:11:06Z")

</div>

Yeah I think NotePlan and Hook will combine really well

---

<div class="post-metadata">

**Author:** ![Jan\_Salomonsson](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jan_salomonsson/32/181_2.png) [@Jan\_Salomonsson](https://discourse.hookproductivity.com/u/Jan_Salomonsson)\
**Post date:** [July 11, 2019, 8:13am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/6 "2019-07-11T08:13:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grahamb](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/grahamb/32/369_2.png) [@grahamb](https://discourse.hookproductivity.com/u/grahamb)\
**Post date:** [July 13, 2019, 6:00am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/7 "2019-07-13T06:00:47Z")

</div>

I put together some scripts to integrate Hook with NotePlan

They work with both notes and dates.

### Get Name

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Jan\_Salomonsson](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/jan_salomonsson/32/181_2.png) [@Jan\_Salomonsson](https://discourse.hookproductivity.com/u/Jan_Salomonsson)\
**Post date:** [July 14, 2019, 7:58am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/8 "2019-07-14T07:58:35Z")

</div>

> [@grahamb](#):
>
> lots of awesome stuff

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

---

<div class="post-metadata">

**Author:** ![eurobubba](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/eurobubba/32/227_2.png) [@eurobubba](https://discourse.hookproductivity.com/u/eurobubba)\
**Post date:** [July 16, 2019, 4:31pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/9 "2019-07-16T16:31:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevelw](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/s/ea666f/32.png) [@stevelw](https://discourse.hookproductivity.com/u/stevelw)\
**Post date:** [July 16, 2019, 5:05pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/10 "2019-07-16T17:05:26Z")

</div>

> [@eurobubba](#):
>
> Your New script is working for me if I increase the final delay (before get (the clipboard as text)) to 1 full second.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![brokosz](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/brokosz/32/1233_2.png) [@brokosz](https://discourse.hookproductivity.com/u/brokosz)\
**Post date:** [June 11, 2020, 6:52am UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/11 "2020-06-11T06:52:44Z")

</div>

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…

```auto
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

```

---

<div class="post-metadata">

**Author:** ![LucB](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/lucb/32/2228_2.png) [@LucB](https://discourse.hookproductivity.com/u/LucB)\
**Post date:** [June 11, 2020, 5:10pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/12 "2020-06-11T17:10:43Z")

</div>

> [@brokosz](#):
>
> edTitle

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.

---

<div class="post-metadata">

**Author:** ![brokosz](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/brokosz/32/1233_2.png) [@brokosz](https://discourse.hookproductivity.com/u/brokosz)\
**Post date:** [June 11, 2020, 6:05pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/13 "2020-06-11T18:05:40Z")

</div>

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.

```auto
	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

```

---

<div class="post-metadata">

**Author:** ![EduardMe](https://discourse.hookproductivity.com/letter_avatar_proxy/v4/letter/e/db5fbb/32.png) [@EduardMe](https://discourse.hookproductivity.com/u/EduardMe)\
**Post date:** [June 13, 2020, 6:36pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/14 "2020-06-13T18:36:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brokosz](https://discourse.hookproductivity.com/user_avatar/discourse.hookproductivity.com/brokosz/32/1233_2.png) [@brokosz](https://discourse.hookproductivity.com/u/brokosz)\
**Post date:** [June 13, 2020, 10:00pm UTC](https://discourse.hookproductivity.com/t/noteplan-integration-scripts/527/15 "2020-06-13T22:00:38Z")

</div>

Hi Eduard, 🙂

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
