Hook doesn't work with VSCode

When I use ^H to invoke hook in VSCode, then it will say

No linkable item found in Code.

OS: Monterey 12.4
Hook: 3.7.1(4869) (Scripts version 227)
VSCode: 1.70.2 (Universal)

I find there is no default script in Hook

Thatā€™s because it works out of the box with Hookā€™s default integration system. At least it did per Visual Code Studio - #2 by Noaal .

Did you update recently? Has anyone else had issues with VS Code?

After I reboot my Mac, it worksā€¦ May be some user-friendly hints. For example, when user first use hook in vscode, after get permission, tell users it may work after reboot.

1 Like

Thanks for the update. If users see No linkable item found in <App> then the status bar reads:

No linkable item found in Mail. Learn more. :mag_right: Search Hookā€™s bookmarks instead?

That web page includes rebooting as one of the steps, after 1. tccutil reset Accessibility com.cogsciapps.hook

Taking advantage of this discussion to complain that Hook tries to hijack Cntl-H, one of the most useful keystrokes in bash, terminal apps, vim, etc. (see link). I have a keyboard with the Cntl key where it belongs, to the left of the A key, and I almost never have to reach for the Backspace key (Cntl-H), the Escape key (Cntl-[), etc. Thank goodness Hook allows me to change its hotkey.

Yep. We didnā€™t initially use ^H, but it was recommended to us and many people like it. The mnemonic value is important for many users as they get to learn Hook. Of course many prefer something different, which is why we allow people to turn that one off, and to use a different shortcut. Life in the world of trade-offsā€¦

It would be good for Hookā€™s welcome board to enable users to change the keyboard shortcut right then and there, instead of having to go to the Preferences later.

Some additional suggestions, hook in the function of the performance is very good, but from the perspective of interaction there is still a lot of room for improvement, for example, when the user uses the call out hook, but also need additional shortcuts or mouse clicks to copy the link to the clipboard, in my understanding, when the user calls out hook will naturally want to get the appropriate link and then paste it elsewhere, so why not the default will be copied to the clipboard?

thanks for the feedback, @icecity96 , and all.

A global keyboard shortcut can be set for copying links.

because Hook window makes available many functions. Users does not always want to wipe the keyboard, which may have other information. For instance, the user might simply want to Hook to Copied Link and then paste the original link elsewhere.

Hi!

Yes, Iā€™ve had issues, before, then it somehow started working. Maybe after a system update. Most recently, the issue arose after bcoming interested in creating deep links using vsCodeā€™s url scheme which, per OliverBalfourā€™s comment , accepts colon delimited row and column info. To me, this seems like a url protocol that could enable deep hooklinks to docs opened in vsCode.

The reason I am raising this here, in this thread, is because attempting to enable it with scripting breaks Hookā€™s ability to detect vsCode docs, resulting in ā€œNo linkable item foundā€ messages, thereafter. And the kicker is that this stays broken even once you reset the scripts back to their defaults. And after you toggle Hookmarkā€™s automation permissions off and back on, reset its Accessibility permissions, restart, etc. I am no longer willing to touch it after running two system updates to get it back working. Suffice to say, having made the mistake of editing the script again after the first update corrected it, I was lucky a sonoma patch was available immediately after.

To justify my attempt at scripting, it is probably worth noting that vsCode supports all manner of document formats ā€“ many natively, but a pile more through its endless vast extension marketplace. Also, itā€™s free, and built on an open source platform with a corresponding open source version, vsCodium, that boasts everything but the proprietary Microsoft extensions. But I digressā€¦

The point, here, is that vsCode is the worldā€™s MOST USED IDE, and its url scheme supports linking directly to a given row and column within a document. And finder and browsers can already resolve these links. Therefore, my feeling is that it is worth a shot to figure out how to enable Hookmark, with all its access permissions and brilliantly resilient links, to process links formatted as hooklink:row:col when resolving paths for which vscode is the default opener.

However, I donā€™t know whatā€™s on the roadmap, and whether such functionality would be considered a priority. But in order to avoid having to update my os with every attempt to implement this, Iā€™m asking: what appleScript will satisfy the ā€œ(vs)Code requires a ā€˜get Urlā€™ scriptā€ requirement in the ā€œOpen Itemā€ tab of the scripting pane for vsCode? Because, for reasons unknown to me (but likely known by you), a ā€œGet Urlā€ script must evidently replace the existing hooklink creation facility, which already works, kind of, in order for the custom url scheme to be implemented in ā€œGet Itemā€.

In summary, if the ā€œGet Addressā€ requirement can be satisfied/bypassed with a bare bones script or verbatim copy of whatever existing logic is used under the hood ā€“ and which sometimes works out of the box, barring failed edits and the ineffective reset mechanism ā€“ then it seems the last step would be simple: parse the clicked-on hook url into 1) the hook link and 2) any manually-appended row and column suffix, then sandwich the resolved file path between ā€˜vscode://file:ā€™ and the column and row suffix parsed from the original link andā€¦ Voila! Deep hooklinks to docs opened in vscode.

Can you recommend an applescript to accomplish this parsing and reconstruction of a link url for the ā€œOpen Itemā€ tab, and one to satisfy the ā€œGet Urlā€ prerequisite?

Thanks for any help,
Ben

Thank you, @Nardo .

We will have a look.

Sorry currently appending row and column number would not work for hook link. I just created an issue request for this.

If you just want vscode url, here is the Get Address script for VSCode that can get url like ā€œvscode://file/ā€¦ā€. Unfortunately, Hookmark canā€™t get the row and column number. You can manually append column and row number to it. You donā€™t need open item script for it because it is vscode URL already.

Summary
use scripting additions
use framework "Foundation"


on urlDecode(input)
	tell current application's NSString to set urlString to stringWithString_(input)
	set theDecodedURL to urlString's stringByRemovingPercentEncoding -- 4 is NSUTF8StringEncoding
	return theDecodedURL as Unicode text
end urlDecode


tell application "System Events"
	
	tell process "Code"
		set theURL to value of attribute "AXDocument" of window 1
		set fp to text 8 thru -1 of theURL
	end tell
end tell

tell application "Finder"
	set fileName to name of (POSIX file (my urlDecode(fp)) as alias)
end tell

return "[" & fileName & "](vscode://file" & fp & ")"