Hooking Lightroom & Devonthink

I’m looking into using Hookmark to link between Devonthink & Lightroom. Lightroom doesn’t do AppleScript but I have a plugin that uses Lightroom’s URLhandler function such that I can send URLs - lightroom://… - to get information from Lightroom. What would be the best way to do this in Hookmark?

Welcome to Hookmark, @kimaldis .

Is the URL from plugin accessible by AppleScript? If your plugin can put the URL in the clipboard, AppleScript can also get it.

Then you can make Hookmark work with Lighroom as follows:
(1)In Hookmark Settings window->Scripts, click on “+” button at bottom left, select Lightroom and add it to the script llist
(2)Select Lightroom in the script list
(3)In Get address pane of Lightroom, add the script which can get the URL
(4)In Get name pane of Lightroon, add the script which can returen the selected item title
(5)Save the script

Then you can give it a try.

Thank you

That, I think, is where the problem lies, neither Lightroom nor the plugin have any understanding of AppleScript. So I can’t use AppleScript to get a URL from Lightroom

Unless, of course, I can have AppleScript connect to Lightroom using lightroom::confused: and have it send back the URL by return. Past attempts have shown that AppleScript gets messy doing this, though.

So I’ve found a quick and dirty solution, having my Lightroom plugin store the URL in the clipboard so it can be picked up in the get address script as below. It’s messy, though; for a start I can’t use the same method for the get name script because the clipboard gets overwritten.

Digging around in some of the included script some of them seem to be using hook://x-callback-url/ URLs. Is there any documentation for these urls?

set targetURL to "lightroom://com.aldis.chatter/?code=getSourceAddress()"
do shell script "open " & quoted form of targetURL
delay 0.5
set fetchedData to the clipboard

return fetchedData 

Excellent!

You can put title and URL together in a Mardown link, which has a format like this:
TITLE

Return this markdown link and Hookmark can process it.

Does Lightroom have x-callback-url support? I just did search but couldn’t find any info related to this.

Thank you

You mean return a markdown link in the clipboard?

You can set up x-callback in Lightroom using the SDK.

Yes

Do you mean setting up in the App?
Here is an example for using x-callback-url to get url and title from Drafts. The information is returned in the x-callback-url(URL Schemes | Drafts User Guide).

 set callbackURL to "hook://x-callback-url/setCurrentNode%3FrequestID%3D$requestID"
    
    set myURL to "drafts://x-callback-url/getCurrentDraft?" & "&x-success=" & callbackURL
    
    set myScript to "open '" & myURL & "'"
    do shell script myScript
    return callbackURL

Thank you

Do you mean setting up in the App?

You create a plugin that handles it.

Here is an example for using x-callback-url

yes, I found the Goodlinks script which is much the same. I’m just wrapping my head around it now.

cheers

Trying this script but with the myURL variable set to the lightroom:// url for my plugin, I get a ‘no linkable item found in Lightroom’ error. What am I missing? Does my plugin need to modify the x-succes url somehow?

Here is an example x-callback-url that Draft calls back to Hookmark:
“hook://x-callback-url/setCurrentNode?requestID=$requestID&title=file1&url=drafts://open?uuid%3DAF3E45A5-767C-4502-A062-8EBB02459A57”

Here is the steps you can do in your plugin:
(1)URL decode the callbackURL from x-success, you will get hook://x-callback-url/setCurrentNode?requestID=$requestID
(2)Append the title and url of Lightroom item to hook://x-callback-url/setCurrentNode?requestID=$requestID, which will result in a URL looks like below, but with different value of title and url:
“hook://x-callback-url/setCurrentNode?requestID=$requestID&title=file1&url=drafts://open?uuid%3DAF3E45A5-767C-4502-A062-8EBB02459A57”

the title needs be encoded(can’t have special characters, such as space).

(3)Call this URL from your plugin

I’m still getting an empty Hookmark dialog and when I C to get the link it gives me a url from the last time I invoked Hookmark on another app. When I check the x-success my plugin is given it’s exactly hook://x-callback-url/setCurrentNode?requestID=$requestID. I’m guessing but shouldn’t $requestID be set to some kind of unique ID by Hookmark?

“$requestID” is a just a symbol will be used by Hookmark.

Could you please post a sample x-callback-url returned by your plugin?

Thank you

hook://x-callback-url/setCurrentNode?requestID=$requestID&url=lightroom%3A%2F%2Fcom%2Ealdis%2Echatter%2F%3Fcode%3Dlocal%20LrApplication%20%3D%20import%20%22LrApplication%22%20local%20catalog%20%3D%20LrApplication%2EactiveCatalog%28%29%20local%20Source%20%3D%20catalog%3AgetCollectionByLocalIdentifier%28%205972393%20%29%20catalog%3AsetActiveSources%28%20%7BSource%7D%20%29%20&title=aaaaaaaaa

or decoded:

hook://x-callback-url/setCurrentNode?requestID=$requestID&url=lightroom://com.aldis.chatter/?code=local LrApplication = import “LrApplication” local catalog = LrApplication.activeCatalog() local Source = catalog:getCollectionByLocalIdentifier( 5972393 ) catalog:setActiveSources( {Source} ) &title=aaaaaaaaa

For URL:
lightroom://com.aldis.chatter/?code=local LrApplication = import “LrApplication” local catalog = LrApplication.activeCatalog() local Source = catalog:getCollectionByLocalIdentifier( 5972393 ) catalog:setActiveSources( {Source} )

do you mean:
code=local
LrApplication = import “LrApplication”
local catalog = LrApplication.activeCatalog()
local Source = catalog:getCollectionByLocalIdentifier( 5972393 )catalog:setActiveSources( {Source} )

yes, but it’s just a hardcoded collection ID. The collection exists and the code works when tested. I wouldn’t think that a would cause the Hookmark dialog to be empty.

The URL is a special one. But I just tested the above URL, Hookmark is able to parse it.

Could you post your Get Address script?

Also make sure open this URL in your plugin.

Perhaps If you can put markdown link in the clipboard, it would be simpler than implemented in x-callback-url.

Thank you

set callbackURL to "hook://x-callback-url/setCurrentNode%3FrequestID%3D$requestID"

set targetURL to "lightroom://com.aldis.chatter/?code=Hook:getSourceAddress()" & "&x-success=" & callbackURL

set myScript to "open '" & targetURL & "'"
do shell script myScript

return  callbackURL

I tried putting markdown in the clipboard but Hookmark showed it encoded.

%5Bxxxx%5D(lightroom%3A//com.aldis.chatter/?code=local%20LrApplication%20=%20import%20%22LrApplication%22%20local%20catalog%20=%20LrApplication.activeCatalog()%20local%20Source%20=%20catalog:getCollectionByLocalIdentifier(%206400018%20)%20catalog:setActiveSources(%20%7BSource%7D%20)%20)%0D

Is this the markdown link you passed to Hookmark or it is returned by Hookmark?