Created
November 14, 2013 02:57
-
-
Save shanzhong/7460581 to your computer and use it in GitHub Desktop.
My AppleScript for custom URL handler skimmer://<pdf file name>.pdf#page=N that opens PDF files in Skim and jumps to the specified page N.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Inspired and modified from http://drosophiliac.com/2012/09/an-academic-notetaking-workflow.html | |
| --It creates a custom URL handler skimmer:// for opening PDF files in Skim and jumping to the specified page | |
| --Usage: Copy and paste this into AppleScript Editor, and save as an app named Skimmer.app. Then, change the info.plist file within the app bundle and add the contents at the end of this gist. | |
| --BEGIN main script | |
| on open location skimmerURL | |
| set skimmerPath to do shell script "php -r 'echo urldecode(\"" & skimmerURL & "\");'" | |
| --When the skimmer url is clicked, we have to extract the arguments from the url and pass them to this script. | |
| set oldDelims to AppleScript's text item delimiters | |
| --This saves Applescript's old text item delimiters to the variable oldDelims. | |
| set newDelims to {"skimmer://", "#page="} | |
| --This sets the variable newDelims to our new custom url handler prefix and the prefix for the page number argument. | |
| set AppleScript's text item delimiters to newDelims | |
| --This sets Applescript's text item delimiters to the newDelims. | |
| set pdfPath to item 2 of the text items of skimmerPath | |
| --This extracts the file name from the passed url using the new text item delimiters. The file name is the second text item | |
| set pdfPath to do shell script "python -c \"import sys;print(sys.argv[1].replace('/',':'))\" \"" & pdfPath & "\"" | |
| set pdfPage to item -1 of the text items of skimmerPath as integer | |
| --This extracts the desired page number because it is the last argument of the passed url. | |
| set AppleScript's text item delimiters to oldDelims | |
| --This resets Applescript's text item delimiters. | |
| tell application "Skim" | |
| open pdfPath | |
| go document 1 to page pdfPage of document 1 | |
| end tell | |
| end open location | |
| --END main script | |
| --Put the following contents at the end of the info.plist file inside the app bundle, inside the biggest <dict>...</dict> tag | |
| <key>CFBundleIdentifier</key> | |
| <string>com.drosophiliac.AppleScript.Skimmer</string> | |
| <key>CFBundleURLTypes</key> | |
| <array> | |
| <dict> | |
| <key>CFBundleURLName</key> | |
| <string>Skimmer</string> | |
| <key>CFBundleURLSchemes</key> | |
| <array> | |
| <string>skimmer</string> | |
| </array> | |
| </dict> | |
| </array> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment