Skip to content

Instantly share code, notes, and snippets.

@tlkahn
Created January 28, 2025 02:20
Show Gist options
  • Save tlkahn/57d39841e021cb3d3876241d0606f5e4 to your computer and use it in GitHub Desktop.
Save tlkahn/57d39841e021cb3d3876241d0606f5e4 to your computer and use it in GitHub Desktop.
skimpdf link creation

Below is a working example of how to create (1) a simple AppleScript application that registers a custom URL scheme, and (2) links that open a given PDF at a given page in Skim.

────────────────────────────────────────────────────────

  1. Create the AppleScript ────────────────────────────────────────────────────────
  2. Open “Script Editor” (in /Applications/Utilities).
  3. Create a new document and paste this script:

-- This handler is called when a URL with the scheme "skimpdf://" is opened. -- Example URL: skimpdf:///Users/yourUser/Desktop/paper.pdf?page=5

on open location theURL try (* theURL is something like: "skimpdf:///Users/yourUser/Desktop/paper.pdf?page=5" *)

    -- Strip off the "skimpdf://" prefix
    set AppleScript's text item delimiters to "skimpdf://"
    set pathAndParams to text item 2 of theURL

    -- Separate path from the "?page=" parameter
    set AppleScript's text item delimiters to "?page="
    set pdfPath to text item 1 of pathAndParams
    set pageNumber to text item 2 of pathAndParams

    -- Open file in Skim, go to that page
    tell application "Skim"
        activate
        open POSIX file pdfPath
        tell document 1
            go to page (pageNumber as integer)
        end tell
    end tell
    
on error errMsg
    display dialog "Error: " & errMsg
end try

end open location

  1. In Script Editor’s menu, choose File → Export…
    • File Format: “Application”
    • Give it a name (e.g., “SkimPDFOpener”) and save it somewhere convenient.

──────────────────────────────────────────────────────── 2. Configure the Info.plist to register "skimpdf" scheme ────────────────────────────────────────────────────────

  1. In Finder, right-click your newly saved application, and choose “Show Package Contents.”
  2. Go into the “Contents” folder and open “Info.plist” in a text editor (TextEdit or Xcode).
  3. Inside the main … , add:

CFBundleURLTypes CFBundleURLName Skim PDF Opener CFBundleURLSchemes skimpdf

  1. Save Info.plist.
  2. (Re)launch your AppleScript application by double-clicking it, so macOS registers the new scheme.

──────────────────────────────────────────────────────── 3. Test it ──────────────────────────────────────────────────────── • Construct a URL in the form:
skimpdf:///absolute/path/to/file.pdf?page=NN
Example:
skimpdf:///Users/yourUser/Desktop/2310.01798v2.pdf?page=1

• Open that URL (for instance, in Safari, Terminal with “open 'skimpdf:///…'”, or a Markdown link).
• macOS should launch your script, which in turn launches Skim, opens the PDF, and jumps to the specified page.

──────────────────────────────────────────────────────── Notes / Tips ──────────────────────────────────────────────────────── • The path in the URL must be a valid absolute POSIX path. If your PDF filename has spaces or special characters, you’ll need to URL-encode them (e.g., “%20” for spaces).
• Only Skim is directly supported here because it has AppleScript support. Preview in macOS does not offer an official URL scheme or AppleScript command to jump to specific pages.
• If nothing happens, ensure that:

  1. Your AppleScript app is running once to register its scheme.
  2. The Info.plist is edited correctly and saved.
  3. Your path does indeed exist, and page numbers are valid.

With that in place, you can embed these custom links (like “skimpdf:///path/to/file.pdf?page=5”) in your Markdown or other documents. Clicking them will open Skim directly at the specified page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment