Deep links to Skim have stopped working

My existing deep links to Skim seem to have stopped working properly and attempts to create new ones only link to the PDF itself and not to the position in the PDF. Skim was recently upgraded to Version 1.6.10 (140). Hook is Version 3.5 (4736; Integration v. 213). macOS is 11.6.5.

1 Like

Welcome to the Hook Productivity Forum , @arduncan5 . Sorry, I thought I had replied to this yesterday. I have tested with Version 1.6.10 (140) and Hook 3.5 and macOS 12. Works fine. I also tested this on Catalina, works fine there too for me.

I use Skim quite a bit too.

I will have a look at Skim releases notes to see if there may be a clue.

2022-05-04 20:27. I corrected my reply because earlier I misread the OP as referring to macOS 10.11.

If you look at Hook > Preferences > Integration > Skim > Get Address, do you see the following?

use scripting additions
use framework "Foundation"
property NSMutableCharacterSet : a reference to current application's NSMutableCharacterSet


on urlEncode(input)
    tell current application's NSString to set rawUrl to stringWithString_(input)
    set charset to NSMutableCharacterSet's URLQueryAllowedCharacterSet's mutableCopy
    charset's removeCharactersInString:"?"
    set theEncodedURL to rawUrl's stringByAddingPercentEncodingWithAllowedCharacters:charset
    return theEncodedURL as Unicode text
end urlEncode

tell application "Skim"
    set fPath to POSIX path of (get file of document 1)
    set pn to index of current page of document 1
    
    set fName to name of document 1
    set hasSelection to false
    set hasSelectionBounds to false
    set selBounds to selection bounds of document 1
    if selection of document 1 is not {} then
        tell (do shell script "osascript -e 'tell app \"Skim\" to selection of document 1'")
            set s to word 2
            set e to word 4
        end tell
        set hasSelection to true
    else if selBounds is not {} then
        set xx to item 1 of selBounds
        set yy to item 2 of selBounds
        if xx is not equal to 0 or yy is not equal to 0 then
            set hasSelectionBounds to true
        end if
        
    end if
    
end tell

if hasSelection then
    get "file://" & urlEncode(fPath) & "#p=" & pn & "&x=0&y=0&s=" & s & "&e=" & e
else if hasSelectionBounds then
    get "file://" & urlEncode(fPath) & "#p=" & pn & "&x=" & xx & "&y=" & yy
else
    get "file://" & urlEncode(fPath)
end if

Is it possible youā€™ve overridden the integration?

That script is in place but at a slightly different path to view it: Hook > Preferences > Scripts > Skim > Get Address.

Is there anything else you would like me to test or check? I have the Setapp version of PDFpen but am not sure if that should work with deep links.

Thatā€™s correct.

First, could you please download this PDF from CogZestā€™s website: https://cogzest.com/wp-content/uploads/2021/03/Deep-PDF-Linking-Worked-Example.zip

It contains a file called ā€œMental Perturbance.pdfā€

Then could you please put this link in Safariā€™s address bar hook://file/CVqCquuAD?p=RG93bmxvYWRzL1Jlc291cmNlcw==&n=Mental%20Perturbance%2Epdf#p=24&x=0&y=0&s=2071&e=2388 ? macOS should prompt you to open Hook with it.

Please let us know whether that opens the ā€œMental Perturbance.pdfā€ file and scrolls to page 24 (known as page 51 in the header of that file).

Secondly, using Skim, could you please select some text in that PDF, invoke Hook, and do Copy Link or Copy Markdown Link, and paste the resulting link here , formatted as code. (thereā€™s a </> code tool in this forumā€™s editorā€™s formatting toolbar).

Thirdly, please let us know what selection tool you use in Skim when you invoke Hook to get a deep link: Skim > Tools menu > ā€¦

  • Select tool , or
  • Text tool

Thank you for your help with this.

  1. Works correctly and opens at that page.
  2. [Mental Perturbance.pdf](hook://file/CXRa4cFNV?p=YXJkL1Jlc291cmNlcw==&n=Mental%20Perturbance%2Epdf#p=7&x=0&y=0&s=64&e=145). Should open at p.7/34 and does so.
  3. Text tool.

I have investigated further and may have found a clue to the problem. The document I was having the problem with was stored in DEVONthink and was opened in Skim directly from there. If I export the same document from DEVONthink to the file system then deep links to that document now work fine! Hope that helps!

Yes, accessing Hook in files that are stored inside DEVONthinkā€™s database carries a risk because those files are not meant to be treated as regular files. DEVONthink can delete those files at any time (replacing them with other files). For example, if you unsync your DEVONthink database and then resync it, I would expect all the file names to be different.

We have a help page on Using Hook With DEVONthink that contains a section on ā€œLinking outside of DEVONthinkā€. Iā€™ve renamed the section to Using external apps to view/edit files that are stored in DEVONthink. This explains the issue. Iā€™ve added some text to it (though idea was there).

When in the context of some app (like TextEdit, Skim or Preview) you invoke Hook on any file, Hook will identify that file using the address (URL) that is relevant to that app. Hook does not know that you used DEVONthink to launch Skim (or Preview, etc.). For Skim, Preview and most file-based apps, Hook identifies the file using a hook://file/ URL (which is based on the fileā€™s ā€œpathā€).

Having said that, Iā€™m not sure exactly what youā€™re seeing based on your OP (original post) :

It sounds like youā€™re saying that when you use a prior link to the file, the file does not open. Or is it just that it does not go to the deep location?

If the file does not open, it may be that DEVONthink has deleted the original file (even though the file is still in its database), or changed it in some other way that broke its path. (What looks like the ā€œsameā€ file in DEVONthink, may be a different one as far as the operating system is concerned.)

I imagine this could happen if there is a sync event. I donā€™t know if DEVONtechnologies explains all the conditions under which it might do this kind of thing. App developers donā€™t have to detail what happens in their ~/Library/Application Support folder.

Could you please paste one of those PDF links here (or send us a PM or email with it)?

But based on your next comment, what you are experiencing may be different:

In our experience, deep links with Skim work quite well. Basically, Hook simply relies on Skimā€™s AppleScript to scroll to get the current path and location; then it converts that to a link.

Could you please test the AppleScript above on Skim PDF using Script Editor, as follows

  1. open a PDF file in Skim (from DEVONthink).
  2. select some text
  3. copy the AppleScript above
  4. paste it in a new Script Editor file. You can use Hook to New >Script Editor from this page to get the new file.
  5. Then hit the ā€œ>ā€ run button.

this will produce a URL. But if you get an error message that might tell us what is happening.

If those files have in fact been deleted, you can still access Hookā€™s links to them. Use āŒ˜F in Hook to find the links (based on the targetā€™s names). then you can focus on the link and do Copy All Links. You can then associate those links to another item.

NB, Files that are merely indexed by DEVONthink will not be deleted by DEVONthink of course. The issue just affects files that are in DEVONthinkā€™s database.

When I use a prior link to the file, the file itself opens but does not go to the deep location. As I cannot create a new deep link (in Skim) for a file opened from DEVONthink I amm beginning to suspect that I may not have tested those links prior to the Skim upgrade as I though that I had done.

Links are as follows:

  1. File opened in Skim from within DEVONthink: [Ewart et al (2004a) - Petrology and geochemistry of early cretaceous bimodal continental flood.pdf](hook://file/CZvg5mPwF?p=cGRmLzk=&n=Ewart%20et%20al%20%282004a%29%20%2D%20Petrology%20and%20geochemistry%20of%20early%20cretaceous%20bimodal%20continental%20flood%2Epdf#p=22&x=0&y=0&s=4262&e=4279)
  2. File opened in Skim from the file system: [Ewart et al (2004a) - Petrology and geochemistry of early cretaceous bimodal continental flood.pdf](hook://file/CZvvzC41Z?p=YXJkL1RlbXA=&n=Ewart%20et%20al%20%282004a%29%20%2D%20Petrology%20and%20geochemistry%20of%20early%20cretaceous%20bimodal%20continental%20flood%2Epdf#p=22&x=0&y=0&s=4262&e=4279)

In both cases I attempted to save a deep link to the same point inside the document. In case 1 the file opened from the link, but not at the deep link position. In case 2 the file opened correctly at the deep link position.

I couldnā€™t carry out the sequnce of 5 actions you requested as I couldnā€™t see the AppleScript you referred to.

there seem to be two issues.

What do you mean by ā€œsaveā€. Inside what document?

Do you mean create a hook, using Hook to Copied Link? Or do you mean pasting a deep link inside a file, like a file opened in TextEdit ?

Here where is the link in question? Is it in a file somewhere? Or is this a hook (i.e., visible when you invoke Hook on a file)?

If you are referring to hooks, then please note that there is a limitation in Hook that there is only one Hook allowed between a given file and a given PDF. This is by design, to prevent cluttering the Hook window with multiple hooks to the same PDF. We also felt that this use case is better served by pasting links to the PDF inside a file. Having said that, we have come up with a UI design that simplifies this use case, which we do plan to support.

My apologies for not making myself clear, let me spell things out in more detail. The process I have followed is to select a phrase in a PDF using Skim, invoke Hook, and then select ā€œCopy Markdown Linkā€. I then paste this link into a markdown file in Obsidian. I then view the file in preview mode in Obsidian and click on the link to test it. When I click on the link to a PDF which was opened in Skim from DEVONthink then the PDF opens, but not to the page containing the phrase that was selected when the deep link was created. When I click on the link to a PDF which was opened in Skim from the file system. then the PDF opens at the page containing the phrase that was selected when the deep link was created. This behaviour applies to book-length PDFs, please see further comments below).

I had not realised the limitation in Hook that there is only one Hook allowed between a given file and a given PDF.

I have been doing some further testing and the results are consistent, but weird! If I open a PDF from DEVONthink and if the PDF is ā€œlongā€ (book length, 300+ pp) then the deep link opens to the PDF, but not to the selected phrase. If the PDF is shorter (I tested with a 47 page article) then even if this is opened in Skim from DEVONthink, then the deep link opens correctly to the PDF and the selected phrase. I have tested this with two books (378 and 423 pp) and with both Obsidian and Bear as the markdown editors. If the book-length PDFs were opened in Skim from the file system, then deep links work correctly.

1 Like

thanks for clarifying. Weā€™ve had another report of an issue with long PDFs in Skim. We havenā€™t been able to replicate so far but maybe itā€™s dependent on hardware (I have M1 Max, my colleague is using Intel; but both of us with SSD).

Since you are getting correct links, it seems to me that the issue is that Skim takes a long time to deal with the AppleScript with one of the files.

Is it possible that one of the files is stored on a fast storage device (e.g., SSD), and the other (the one with the problems) is stored on a slower medium (e.g., spinning hard disk)?

Next step after that would be for us to provide you with an AppleScript to test opening the link in Script Editor.

Thank you for all the info and steps.

A user with the same issue said via PM that it went away after he reinstalled Skim. You might want to try an old fashion reboot too.

A reboot didnā€™t help, but reinstalling Skim has cured the problem! I suspect that things must have gone awry during the recent Skim update.

Thanks for all your help.

1 Like

Unfortunately, Iā€™m experiencing the same issue and while I was following all the recommendations above, deep links still donā€™t work for me.

UPD. False alarm, sorry for that. My problem was solved once I allowed access to my Documents folder.

1 Like

Welcome to the Hook Productivity Forum , @jrnv. Glad to see the issue is resolved. I love Skim , and deep linking to PDFs. I started using Skim so long ago I canā€™t even remember when. 2004 or 2005 (if itā€™s that old?)

The same issue occurs to me but reinstalling Skim doesnā€™t help. Thus I move pdfs from Devonthinkā€™s database to desktop and index the files and deep links get back to normal.

Thank you for detailed discussion above, it really helps.

Sorry, I missed this step in your description. That is the issue, and itā€™s not a bug.

  1. If you select or open a PDF in DEVONthink and invoke Hookmark, the file will be addressed with the x-devonthink-item URL scheme
  2. if you open a file in Skim, then invoke Hookmark on it, Hookmark will use the hook://file/ scheme (with parameters for deep linking).

They are different URL (address) schemes. Hookmark does not know they are the same file.

compare

Using external apps to view/edit files that are stored in DEVONthink

in:

Using Hook with DEVONthink by DEVONtechnologies ā€“ Hookmark

Itā€™s not recommended to use Hookmark to get URLs to PDFs that are stored in a DEVONthink database but opened in a different app than DEVONthink. The reason is that Hookmarkā€™s URLs (hook://file/) are based on Finder information (filenames). And DEVONthink does not guarantee integrity of those file names (nor should it). Hookmark and Skim have no knowledge of DEVONthink IDs outside of DEVONthink.

I believe DEVONthink has its own deep PDF links, which you could use instead of Hookā€™s if your files are in DEVONthink databases.

If the files are merely indexed by DEVONthink, then youā€™re OK.