Hook + Logseq = ❤️

Welcome to the Hookmark Forum , @Kullenej . We will publish a tweak with additional instructions very soon. Meanwhile, we urge anyone who wants Logseq automation to contact the Logseq devs to ask them to spend a few minutes to add an API for linking, otherwise their software is in a walled-garden. Or some may wish to contribute directly if you’re a dev and user of that software. Cf Manifesto for Ubiquitous Linking. Obsidian has extensive automation for linking: https://hookproductivity.com/help/integration/using-hook-with-obsidian/ .

1 Like

The script our user provided. I did a small change by creating a variable for graph name.

#change YourGraphName to your graph's name
set graphName to "YourGraphName"

set savedClipboard to the clipboard
delay 0.05
set the clipboard to ""
delay 0.05
tell application "Logseq" to activate
tell application "System Events"
	keystroke "c" using {command down, shift down}
	delay 0.05
	repeat 10 times
		try
			set blockRef to the clipboard
			if blockRef is not equal to "" then
				exit repeat
			end if
			keystroke "c" using {shift down, command down}
		end try
		delay 0.05
	end repeat
	set blockUrl to "logseq://graph/" & graphName & "?block-id=" & characters 11 thru -5 of blockRef as string
	keystroke "a" using {command down}
	delay 0.05
	keystroke "c" using {command down}
	delay 0.05
	set blockContents to the clipboard
	delay 0.05
	set blockLength to (get length of (blockContents as text))
	if blockLength is less than 32 then
		set linkTitle to blockContents as string
	else
		set linkTitle to (characters 1 thru 32 of blockContents as string) & "..."
	end if
end tell
set the clipboard to savedClipboard
return "[" & linkTitle & "](" & blockUrl & ")"

In order to make this script work, In Logseq settings > Edit Config.edn, add the following line:

:editor/copy-embed “mod+shift+c”
to
:shortcuts {
}

After edit, it should look like this:
:shortcuts {
:editor/copy-embed “mod+shift+c”
}

Please let us know your experience with it.

2 Likes

Thank you! I’m actively engaging the Logseq forum for this as well.
But unfortunately, I can’t get the script to work.
Here is how it looks in Hookmark:

I have also restarted both apps, but no luck!

Thanks!!

And here is my Logseq config.edn:

You put the shortcut in the comments(they have green color). I did the same thing in the beginning. Please put the shortcut in shortcuts{} with red color. Also before invoke Hookmark, please put the mouse cursor in one of the blocks.

1 Like

Thank you! Worked like a charm.

1 Like

Any chance for a more easy and more convenient Logseq integration in the near future?

The ball is in Logseq’s court for this one.

Thanks, have asked there, too.

1 Like

Hello Professor, I have been using this script for a while but it keeps giving me problems. When I hook a block in logseq, the pop-up hookmark window often appears as shown in the picture, that is, there is a “/” between each letter. The links obtained in this way cannot be hooked.
When this kind of problem occurs, I need to restart hookmark and re-operate before it returns to normal. But this problem occurs so frequently that it greatly affects my use.
I really hope you can make some modifications to this script to make it more perfect, thank you very much!


My various program/system versions are as follows:
Mac: Sonoma 14.2.1(M1 Pro)
hookmark: Version 6.0.1 (5788; Integration v. 314)
logseq: 0.10.5

Sorry about this issue, @xiangshu .

When this issue happens, what’s the block text? Could you please share it with us?

Thank you

Thank you for reply! When I copied the block text, it looked like this:
[{/{/e/m/b/e/d/ /(/(/6/5/c/c/a/b/0/6/-/1/3/e/f/-/4/7/5/4/-/a/9/0…] (logseq://graph/LogseqIntelligence?block-id=6/5/c/c/a/b/0/6/-/1/3/e/f/-/4/7/5/4/-/a/9/0/7/-/d/0/4/4/7/e/d/f/e/2/4/a)

If I hook this text with other files, logseq will warn me that this block cannot be found because there is a problem with the “block-id”.

Is this the exact text in Logseq or it is from Hookmark’s copy link?

Thank you

It is from Hookmark’s copy link.

Is it possible you share the original block text? Only if you can reproduce the error with this same block.

Thank you

Of course, the information is below:

  1. The original block text from logseq:

[[Skim]] PDF

  1. The block embed from logseq:
    {{embed ((65ccab06-13ef-4754-a907-d0447edfe24a))}}
  2. Bad link in Hookmark:
    [{/{/e/m/b/e/d/ /(/(/6/5/c/c/a/b/0/6/-/1/3/e/f/-/4/7/5/4/-/a/9/0…] (logseq://graph/LogseqIntelligence?block-id=6/5/c/c/a/b/0/6/-/1/3/e/f/-/4/7/5/4/-/a/9/0/7/-/d/0/4/4/7/e/d/f/e/2/4/a)

Is this information what you need? Please feel free to tell me if it’s not enough, thank you!

I copied the embed text to a block, but it seems I can’t reproduce the problem. Did I do embed right?

[{{embed ((65ccab06-13ef-4754-a90…]
(logseq://graph/YourGraphName?block-id=65d113be-5b6f-453b-b3f4-8fb4b0b93c3c)

Yes, you should do it right. However, this error doesn’t occur every time. Sometimes it takes about ten times(ctrl+H) to appear. Maybe you can try it a few more times.
In addition, this problem is not only occured in this block, other blocks may also have problems. So you can also try it with other blocks. :heart:

And I have another question.
The script currently used for logseq in hookmark is designed to obtain result like this: [block content](block URL). Therefore, the shortcut keys are used in the script to “Copy a block embed pointing to the current block”, obtain the block embed and then convert it to block-id, and finally use it to form “[block content] (block URL)”.

But I found that the “block URL” can be copied directly from the block right-click menu of logseq. For example, my “problem block” was copied like this: logseq://graph/LogseqIntelligence?block-id=65ccab06-13ef-4754-a907-d0447edfe24a.

Can this operation be used to improve the script?
Sorry, I haven’t learned how to edit scripts, so I don’t know if this operation is feasible.

Thank you for the info, @xiangshu .

Yes, I can reproduce the problem sometimes now.

Currently Hookmark uses the shortcut of “Copy block URL” to get the block URL, not by parsing the block content. Hookmark copies the block content simply to get the title.

For some reason , sometimes that shortcut returns the content of the block, instead of the URL. Hookmark can’t do much about this.

On my mac, invoke Hookmark again normally solves the problem.

Thank you