Forked from fractaledmind/Insert Markdown Links for current Skim page (DEVONthink URL)
Last active
December 20, 2015 23:39
-
-
Save fractaledmind/6214254 to your computer and use it in GitHub Desktop.
REQUIRED PROGRAMS: -- Skim -- TextMate (I have alternate code for TextEdit as well) This script offers you a dialog box with two options: (1) insert a Markdown formatted Inline Link to the current page of the pdf you are viewing in Skim at your cursor position in TextMate, or (2) insert a Markdown formatted Reference Link to the page. Either lin…
This file contains 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
(* INSERT MARKDOWN LINKS OF CURRENT PAGE OF SKIM PDF INTO TEXTMATE | |
-- created by Stephen Margheim | |
-- 06 July 2013 | |
-- open source | |
*) | |
tell application "Skim" | |
(* PART ONE: | |
Choose your Link | |
*) | |
set number_of_Note3 to (get text for note 3 of page 1 of document 1) as string | |
--display the dialog box with handler at end of script | |
set LinkType to my chooseLinkType({"Reference Link", "Inline Link"}) | |
if LinkType is 0 then return | |
(* PART TWO: | |
Insert your Chosen Link | |
*) | |
tell document 1 | |
--get Skim p# | |
set notePage to get index of current page | |
--get p# printed on the pdf (requires you to manually alter Note 3) | |
set theRealPage to notePage + number_of_Note3 as string | |
--get Custom URL and Title of the pdf | |
set CustomURL to get text of note 1 of page 1 | |
set pdfTitle to (get extended text of note 1 of page 1) as string | |
--create Reference Link if chosen | |
if LinkType is 1 then | |
set FinalText to "[" & pdfTitle & " (p. " & theRealPage & ")]: " & CustomURL & notePage | |
--create Inline Link if chosen | |
else if LinkType is 2 then | |
set FinalText to "[" & pdfTitle & " (p. " & theRealPage & ")]" & "(" & CustomURL & notePage & ")" | |
end if | |
--insert whichever link type you selected into TextMate | |
tell application "TextMate" | |
activate | |
insert FinalText | |
end tell | |
(* If you don't have TextMate, here's the script for the universal Mac program TextEdit. To alter the code, merely delete or comment-out the TextMate tellblock and uncomment this block: | |
*) | |
-- tell application "TextEdit" | |
-- activate | |
-- make new word at end of text of document 1 with data FinalText | |
-- end tell | |
end tell | |
end tell | |
(* HANDLER *) | |
on chooseLinkType(typeList) | |
display dialog "Insert Inline or Reference link to currently viewed page of pdf?" buttons {"Inline", "Reference"} default button {"Inline"} | |
if result = {button returned:"Inline"} then | |
return 2 | |
else if result = {button returned:"Reference"} then | |
return 1 | |
end if | |
return LinkType | |
end chooseLinkType |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment