Is it possible to get block URLs?

I know you can right click a block to “Copy Block URL”, but can this be done through the API?

As you can see a URI for a block is made by current graph name plus the block id, that is stored as the value of id:: property (it’s hidden in the UI but it’s visible in Markdown files for the blocks that have been referenced and for whose the ID has been generated).

So if you have the block ID you can compose the URI, to get current graph name there is an API and there is one to get current block ID (the block where the cursor is placed).

1 Like

Check out how it was implemented here:

(Apple Shortcuts) Logseq Reminders Sync

Hi, the shortcut above uses the API but does not return the currently selected block. Last time i checked i could not retrieve the currently selected block via the API.

You can get the page url by using UI scripting. This Applescript returns the curent page url:

tell application "System Events"
	-- Press "ESC"
  	key code 53
	set the clipboard to ""
	delay 0.5
	
	-- You need to set up this keyboard shortcut for "Copy page Url" in Logseq 
	-- Here: CMD + CTRL + SHIFT + U 
	keystroke "u" using {control down, shift down, command down}
	delay 0.5
	
	set logseqURL to the clipboard
	
	if (logseqURL contains "logseq://") then
		return logseqURL
	end if
	
end tell