Using Applescript to acquire Hook URLs

I’ve been trying to programatically acquire Hook URLs with Applescript. As a complete novice, I’m having trouble. From what I understand, the command “Bookmark from active window” creates a bookmark object. However, when I try and access any properties of the created bookmark, such as the URL only, it succeeds but takes ~1min 20secs to run in Script Editor:

Screen Shot 2021-01-05 at 3.49.27 pm

As I wish to generate these URLs and associate them with extracted snippets of PDFs on the fly, I had hoped such an operation would be instantaneous. Is this even the correct way to go about acquiring Hook URLs? If so, is there something I should be doing to make the script more performant?

Any assistance with this would be greatly appreciated.

Welcome to the Forum

I am curious why you want to do this in Applescript rather than simply using the Copy Link hotkey built into Hook?

“Bookmark from Active Window” as a Hook Applescript command can only get bookmarks for applications which are already supported by Hook through its regular interface. Activating the existing hotkey shortcut is extremely quick; I would imagine it would be equally or more complex to execute your Applescript.

Thanks @rkaplan.

I was pursuing an Applescript solution as that appeared to give me the URL most directly, without preformatted text for the link title. This was because the URL was to be included in a template (also generated by the script) which was appended to Obsidian whenever I highlighted text in PDFpenPro.

Thinking about your comment, though, has lead me to simulate the Copy Link shortcut in Applescript, save the clipboard to a variable, and strip everything but the raw URL. This gets me what I need while also being much quicker - so thanks for the food for thought!

This circumvents the issue, however, of the property lookup of the bookmark being so slow in the original post - any insight into this would also be welcome!

Thanks again.