Some month ago I did the shift to the latest PDFpen Pro (which is now sold and maintained by Nitro instead Smile). running v 13.1 on M! latest OS 12.5.1 with latest Hook 3.7.1.(4869) as of today.
problem: PDF deep-linking via links in note-taking apps broken
how to reproduce:
when I do all the prescribed as usual: selecting text or TOC in PDFpen (or skim) create the specific Hook, paste it and use it:
Result: brings up the pdf at whatever place it was before - but NOT the one in the hook-link
Tried: different links to different places; have the app start the pdf anew; trying in lastest Skim vs PDFpen; different note taking apps including TextEdit etc — no avail
BUT to all surprise
when when I link thru the hook main menu — it finds the location (previously selected and hooked) right away
now, this is of course no work-around or workflow alternative, since
I cant’t maintain a list of deep links in the note-taking app (which is what my workflow wants)
the main menu hooks seem to maintain only one deep-link at a time, the older gets overridden – besides it would be not useful to clutter the main menu list with e.g. 20 different links to places within one pdf file.
and this all worked fine previously
Is this a bug ?
would appreciate some suggestion. It really breaks my workflow
may @LucB you could glance at it first since you seem to oversee the core scripts for this?
I just tested and found that pasting deep PDF links still works in the software configuration and apps you mentioned . Hook app only supports one hook per PDF. So if you want multiple deep links to a given PDF they need to be pasted inside a document, as opposed to Hook. This hasn’t changed since we introduced deep PDF linking…
This is what I did. Now and in the past. And calling the deep link from the pasted link within a document, this is what’s broken. While the one supported via Hook main menu is fine.
Thus
all my deep-links pasted in documents now are rendered useless and just bring up the App (PdfPen pro or Skim). Neither jumps to the deep-linked place any more. Not from markdown documents nor from out of Notes or TextEdit etc
I am puzzled, since the simple single supported via-hook-mai-menu link works fine. If it were a macOS permission problem, why simultaneously for PDFpen and skim both. And BTW of course checked the Sys Prefs:privacy settings: nothing obvious there too.
yes, very much so, nicely. For that reason I switched from PDFExpert (which unfortunately doesn’t get its act together while the scripts never worked reliably for me) to PDFpen pro
PDFpen pro version 13.1 (doesn’t tell me the build in the “About”. Where did you find it? But latest anyway)
So, my link seems malformed, compared to yours?
Using your link no avail either. Your link is supposedly shareable, did I get that right? Or does the share-ability only extend to opening the file altogether, i.e. w/o deep link?
Sorry we could not reproduce the error so we need your help to debug.
If possible, could you please go to Hook Preferences window ->Scripts->PDFpenPro->Open Item, replace the script with the following script and click the save button? Then click one pdf deep link you saved in TextEdit(or other apps). You will see a dialog window, please copy the content and posted here.
After the test is done, please go to Hook Preferences window ->Scripts->PDFpenPro and click on “Reset to Default” button to reset to default script.
Thank you!
Summary
use framework "Foundation"
use scripting additions
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
display dialog "$0"
set fullURL to "$0"
set AppleScript's text item delimiters to "#"
set urlPath to text item 1 of fullURL
if (count of text items of fullURL) is greater than 1 then
set fragment to text item 2 of fullURL
set AppleScript's text item delimiters to "&"
set kvs to text items of fragment
repeat with kv in kvs
set AppleScript's text item delimiters to "="
set k to text item 1 of kv
set v to text item 2 of kv
if k = "p" then
set p to v as number
end if
if k = "x" then
set xx to v
end if
if k = "y" then
set yy to v
end if
end repeat
end if
set fpath to urlDecode(urlPath)
set text item delimiters to "/"
set fn to text item -1 of fpath
set len to length of fpath
set fpath to text 8 through len of fpath
set targetWindow to missing value
tell application id "com.smileonmymac.PDFpenPro"
activate
repeat with i from (count of windows) to 1 by -1
try
set thisWindow to window i
set thisDoc to document of thisWindow
if thisDoc is not missing value and (path of thisDoc) is equal to fpath then
set targetWindow to thisWindow
if index of targetWindow is not 1 then
set index of targetWindow to 1
end if
exit repeat
end if
end try
end repeat
if targetWindow is missing value then
open fpath
set targetWindow to first window
end if
if p is not missing value then
tell targetWindow
set doc to its document
show page p of doc
if yy is not missing value then
if xx is missing value then
xx = 0
end if
tell doc to scroll to X xx Y yy
end if
end tell
end if
end tell
I have two pdfpenpro entries 1. “PDFpen Pro” and 2. “PDFpen Pro 13”. To be sure I entered your script into both “open item” panes and save.
when hitting the deep link within the note-taking file the pdf document comes up as before at just any previous position. No Dialog window opens however. Hook normally does not appear in the task switcher list, but when I search all open windows the only Hook window is the one with the scripts. Is that a permission issue? All my Automation permissions of hook are set as before.
Is the script correct? What App should show with the Dialog Window?
I just downloaded a copy of Nitro PDF Pro for individual from https://www.gonitro.com/features and its bundle id is : com.gonitro.NitroPDFPro.retail, which is also supported by Hook. The latest version is 13.3.
They also have business and sign versions. Could you please let us know which one you downloaded? And run the following command to get the its bundle id(change YourPDFProName to your app name).
osascript -e 'id of app "YourPDFProName"'
Also I guess PDFpenPro with bundle id: “com.smileonmymac.PDFpenPro” is not your default pdf viewer. Otherwise, you will see a dialog box when you click on the deep link. Could you please check?
this is interesting. Although my “check for updates” never brought more then 13.1 which still had a blue logo and was the first I got within the upgrading process from my original smileonmac license, now thanks to your research I downloaded and installed the 13.3.0 (red logo and called Nitro pdfpenpro) from the site you found.
BTW the previous 13.1 was my default pdf reader
Then
Result now com.gonitro.NitroPDFPro.retail
Then making it the default app and installing your scripts into “open item” (there ist still PDFpenporo and PDFpenpro 13 both - not Nitro pdfpenpro !! ) I created a new deep link and Hook requests permissions granted (same text same page as above by Luc)
Here is the script to place in Open Item script for com.gonitro.NitroPDFPro.retail. Sorry it is not obvious. You can see the whole bundle id when you put mouse over it. The visible part of the app name is “Nitro PDF Pro re…”. After paste the script, click on the save button. Also after the test is done, do remember click on “Reset to default” button.
Summary
use framework "Foundation"
use scripting additions
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
display dialog "$0"
set fullURL to "$0"
set AppleScript's text item delimiters to "#"
set urlPath to text item 1 of fullURL
if (count of text items of fullURL) is greater than 1 then
set fragment to text item 2 of fullURL
set AppleScript's text item delimiters to "&"
set kvs to text items of fragment
repeat with kv in kvs
set AppleScript's text item delimiters to "="
set k to text item 1 of kv
set v to text item 2 of kv
if k = "p" then
set p to v as number
end if
if k = "x" then
set xx to v
end if
if k = "y" then
set yy to v
end if
end repeat
end if
set fpath to urlDecode(urlPath)
set text item delimiters to "/"
set fn to text item -1 of fpath
set len to length of fpath
set fpath to text 8 through len of fpath
set targetWindow to missing value
tell application id "com.gonitro.NitroPDFPro.retail"
activate
repeat with i from (count of windows) to 1 by -1
try
set thisWindow to window i
set thisDoc to document of thisWindow
if thisDoc is not missing value and (path of thisDoc) is equal to fpath then
set targetWindow to thisWindow
if index of targetWindow is not 1 then
set index of targetWindow to 1
end if
exit repeat
end if
end try
end repeat
if targetWindow is missing value then
open fpath
set targetWindow to first window
end if
if p is not missing value then
tell targetWindow
set doc to its document
show page p of doc
if yy is not missing value then
if xx is missing value then
xx = 0
end if
tell doc to scroll to X xx Y yy
end if
end tell
end if
end tell
One eye-opener after the other. Would never have noticed that nitro-pedfpen meanwhile had its own place in hook and of course not alphabetical any near to the elder sibling PDFpenpro and moreover that there are so many beasts of the same breed depending on the source of download. feels like the full burden of unhealthy variety much like the jungle of Windows versions in the past.
Anyway, did all that, to com.gonitro.NitroPDFPro.retail hook ’open iteim’
no avail. still no dialog box either, but as usual: last used page
I had a go at some of the above steps, but nothing worked. Deep Linking not working on Nitro PDF Pen (which I downloaded afresh just now, having previously used the Smile branded PDF Pen Pro, which also didn’t work). Some help would be appreciated—I rely heavily on deep linking.
Sorry for the trouble. Could you please send us the following info:
(1)Copy the above command to Terminal, replace “YourPDFProName” with your Nitro PDFPen name and hit the return key. Let us know the result.
(2)Hookmark version
(3)MacOS version
(4)A sample deep link generated by Hookmark