Help circumventing Notebooks limitations with New Item script

I’m aware of Notebook’s limitations with Hook as they are described here and with similar apps that retain the literal file path associated with a Hook link instead of the App-unique url (e.g. Hook will Hook a note to /user/Documents/Notebooks/My Hook Note in Notebooks.txt instead of notebooks://show/My Hook Note in Notebooks.txt).

I was wondering if it was possible to work around Notebook’s limitations when Hooking to a new Note in Notebooks by devising a New Item script that will set a variable notePath to the path of the New Note and return the URL notebooks://path, for example.

I’ve cobbled together this so far to no avail:

tell application "Notebooks"
	activate
	tell application "System Events"
		tell application process "Notebooks"
			tell menu bar item "File" of menu bar 1
				click
				click menu item "New" of menu 1
				click menu item "Markdown" of menu 1 of menu item "New" of menu 1
			end tell
			tell menu bar item "File" of menu bar 1
				click
				click menu item "Save" of menu 1
			end tell
			tell menu bar item "Edit" of menu bar 1
				click
				click menu item "Insert Date" of menu 1
			end tell
		end tell
	end tell
	delay 0.5
	set notePath to path of document 1
	return "notebooks:/" & notePath
end tell

I have near-zero understanding of AppleScript. My difficulties thus far are two-fold:

  1. Hook does not seem to abide by this script at all. Although it will make a new document in Notebooks, I imagine it is only registering my custom template that allows me to make a markdown file that opens specifically in Notebooks.

  2. The result of the line return "notebooks:/" & notePath yields me nothing except notebooks:/ when testing in Script Editor. It seems like the script is not properly retrieving the path of the document for some reason.

Is what I’m looking for at all achievable with Notebooks current limitations in mind? Is this something that I need to instead ask its Developer?

Thanks!

If the developer can have make new note AppleScript support, that would be the test.

UI scripting is unreliable because you don’t know when the previous action is finished.

I modified your script to make it return url. But you make need adjust delay time to get the right url.

tell application "Notebooks"
	activate
	tell application "System Events"
		tell application process "Notebooks"
			tell menu bar item "File" of menu bar 1
				click
				click menu item "New" of menu 1
				click menu item "Markdown" of menu 1 of menu item "New" of menu 1
			end tell
			tell menu bar item "File" of menu bar 1
				click
				click menu item "Save" of menu 1
			end tell
			tell menu bar item "Edit" of menu bar 1
				click
				click menu item "Insert Date" of menu 1
			end tell
		end tell
	end tell
	delay 1
	set notePath to url of document 1
	
	set AppleScript's text item delimiters to "://"
	set res to last text item of notePath
	return "notebooks://show/" & res
end tell


1 Like

Sorry for the late reply. Thank you for your modifications! WOW! Very excited to test out the script.

1 Like