Skip to content

Instantly share code, notes, and snippets.

@annard
Last active September 20, 2019 20:29
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save annard/94791b6e58406f258813 to your computer and use it in GitHub Desktop.
Save annard/94791b6e58406f258813 to your computer and use it in GitHub Desktop.
Import Instapaper articles (exported as CSV from their site) using Numbers into DEVONthink Pro (Office). The web pages will be imported as PDF documents. The folder structure of Instapaper will be replicated in an "Instapaper" top level group for the currently open database.
-- 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
--
-- This program is free software released "as-is"; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-- Get a copy of the GNU General Public License by writing to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-- or visit http://www.gnu.org/copyleft/gpl.html
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