Forked from annard/Import Instapaper CSV.applescript
Created
August 26, 2014 11:48
-
-
Save bunam/10da4c44a249cd674880 to your computer and use it in GitHub Desktop.
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
-- Use Instapaper to export a CSV file of your articles. | |
-- Must have Numbers to open it in. | |
-- Will create PDF documents in /Instapaper/<your folder in Instapaper> groups. | |
-- Be sure to select an open database in DT Pro before you run this. | |
-- | |
-- Created by Annard Brouwer, 24/08/2014 | |
-- Share and enjoy! | |
property kCSVFileType : "csv" | |
property kRootGroupName : "Instapaper" | |
tell application "Numbers" | |
local csvFile, csvDocument, cellRange, aRow, loadURL, theTitle, theGroup | |
set downloadsFolder to path to downloads folder from user domain | |
set csvFile to choose file with prompt "Select a csv file exported from Instapaper" of type kCSVFileType default location (downloadsFolder as alias) | |
set csvDocument to open csvFile | |
tell csvDocument | |
tell first sheet | |
tell first table | |
try | |
set cellRange to cell range | |
my windUp(count of rows) | |
repeat with aRow in rows | |
if address of aRow > 1 then | |
tell aRow | |
set loadURL to the value of first cell | |
set theTitle to value of second cell | |
set theGroup to value of fourth cell | |
my importArticle(loadURL, theTitle, theGroup) | |
end tell | |
end if | |
end repeat | |
my windDown() | |
on error errorMessage number errorNumber | |
my windDown() | |
if the errorNumber is not -128 then display alert "DEVONthink Pro" message errorMessage as warning | |
end try | |
end tell | |
end tell | |
end tell | |
end tell | |
on windUp(numberOfArticles) | |
tell application id "com.devon-technologies.thinkpro2" | |
activate | |
show progress indicator "Archiving Instapaper articles..." steps numberOfArticles | |
end tell | |
end windUp | |
on windDown() | |
tell application id "com.devon-technologies.thinkpro2" | |
activate | |
hide progress indicator | |
end tell | |
end windDown | |
on importArticle(aURL, aTitle, aGroup) | |
local groupPath, theGroup, theRecord | |
tell application id "com.devon-technologies.thinkpro2" | |
try | |
step progress indicator aTitle | |
set groupPath to kRootGroupName & "/" & aGroup | |
if not (exists record at groupPath) then | |
set theGroup to create location groupPath | |
else | |
set theGroup to get record at groupPath | |
end if | |
set theRecord to create PDF document from aURL name aTitle in theGroup pagination no | |
on error errorMessage | |
log message aURL info errorMessage | |
end try | |
end tell | |
end importArticle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment