Jump to content
  • 0

(Archived) batch-add urls applescript question


mrbrigham

Idea

In searching for ways to batch-import from Instapaper into Evernote, I came across Daigo Tanaka's script to do just this: http://daigotanaka.org/?p=1288

 

The script seems to run perfectly (given the Event Log), activating Evernote and pulling the source urls, but invariably Evernote hangs and the script times out. Tanaka himself said he's no applscript expert, and I'm even less of one - does anyone know if there's something in the script that's causing the hang? Or is it simply that Evernote doesn't often play nicely with applescript?

 

Here's the script taken from Tanaka's website:

 

-- Basic settings
set myNotebook to "Instapaper"
set delayInSeconds to 1
set giveUpAfter to 30
set oldToNewOrder to true
-- Function to make sure Evernote is up
to makeSureEvernoteIsUp(giveUpAfter)
    tell application "Evernote" to activate
    tell application "System Events" to set processCount to the count of (processes whose name is "Evernote")
    set trial to 0
    repeat until processCount > 0 or trial > giveUpAfter
        delay 1
        tell application "System Events" to set processCount to the count of (processes whose name is "Evernote")
        set trial to trial + 1
    end repeat
    if processCount = 0 then
        return false
    end if
    return true
end makeSureEvernoteIsUp
-- Main
set prevDelimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
log "Making sure Evernote is up..."
if makeSureEvernoteIsUp(giveUpAfter) = false then
    display alert "Evernote did not start :("
    error number -128
end if
tell application "AppleScript Editor" to activate
set theFile to (choose file with prompt "Select a text file containing URLs")
open for access theFile
set FileContents to paragraphs of (read theFile)
if oldToNewOrder then
    set FileContents to reverse of FileContents
end if
close access theFile
-- Loop through the URLs
set i to 1
repeat with nextLine in FileContents
    if length of nextLine is greater than 0 then
        try
            set myData to every text item of nextLine
            set {theUrl} to {item 1 of myData}
            log {i, theUrl}
            tell application "Evernote"
                set countMatches to count (find notes ("sourceURL:" & theUrl))
            end tell
            if countMatches = 0 then
                log " Adding this article…"
                tell application "Evernote"
                    create note from url theUrl notebook myNotebook
                end tell
                set trial to 0
                repeat until countMatches = 1 or trial > giveUpAfter
                    if makeSureEvernoteIsUp(giveUpAfter) = false then
                        display alert "Evernote crashed? Please try running the script again."
                        error number -128
                    end if
                    set trial to trial + 1
                    delay delayInSeconds
                    tell application "Evernote"
                        set countMatches to count (find notes ("sourceURL:" & theUrl))
                    end tell
                end repeat
                if trial > giveUpAfter then
                    log " …error adding this artile."
                else
                    log " …done"
                end if
            else
                log " Already exists. Skipped."
            end if
        end try
    end if
    set i to i + 1
end repeat
-- Finishing up
set AppleScript's text item delimiters to prevDelimiter
tell application "Evernote"
    synchronize
end tell

 

If anyone has any ideas on the script - or any other method of batch-importing from Instapaper (or any other .csv list of urls), it'd be much appreciated. 

 

 

Link to comment

1 reply to this idea

Recommended Posts

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...