Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zoejessica/729bae14565c928c9a0d to your computer and use it in GitHub Desktop.
Save zoejessica/729bae14565c928c9a0d to your computer and use it in GitHub Desktop.
(*
http://zoesmith.io
Export Bookmarks from Evernote to Pinboard
v1.4 12th September 2012
This script takes selected notes in Evernote and sends an email for each to Pinboard, extracting each note's title, source URL and associated tags. The user should enter their Pinboard email address in the pinboardEmail property below, and can choose a default tag to add to each bookmark on import.
This code is hacky, horrible and non-error checking (but it worked for me). Don't use on thousands of notes at a time, it'll go all crashy. Try selecting one test note first to see if it works for you.
Change log:
v1.4 Added validation of tags with spaces in evernote - now replaced by a hyphen so they form one tag in pinboard
*)
property importTag : "from-evernote" -- the default tag to add when importing to pinboard
property exportTag : "exported-Pinboard" -- the default tag to add to notes in Evernote when they've been mailed
property missingURLTag : "no-sourceurl" -- the default tag to add to notes in Evernote if they were missing a source url and hence weren't mailed to Pinboard
property pinboardEmail : "Your Pinboard email goes here" -- default email address for pinboard uploads, from pinboard.in/settings page
global notesToExport
-- The main program. Gets selected notes from evernote, calls dialog boxes to check/update email and tags, iterates through the notes and calls the mail handler for each.
tell application "Evernote"
set notesToExport to selection
set exportedNotes to 0
set missingURLNotes to 0
if (count of notesToExport) is 0 then -- check that something's selected (e.g. it's not an empty notebook)
display alert "No notes selected" message "Please select some notes in Evernote and try again" buttons {"Oops"}
else
confirmDialogHandler() of me
if (not (tag named exportTag exists)) then
set tagForExportedNotes to make tag with properties {name:exportTag}
else
set tagForExportedNotes to tag named exportTag
end if
if (not (tag named missingURLTag exists)) then
set tagFormissingURLNotes to make tag with properties {name:missingURLTag}
else
set tagFormissingURLNotes to tag named missingURLTag
end if
repeat with currentNote in notesToExport
try
set currentNoteURL to (the source URL of currentNote)
if currentNoteURL is missing value then -- can't export a bookmark without a url.
set missingURLNotes to missingURLNotes + 1 -- this is for reporting after the iteration has finished
assign tagFormissingURLNotes to currentNote
else
set currentNoteTitle to (title of currentNote) -- evernote will always ensure this is "Untitled Note" if empty
set currentNoteTags to (the tags of currentNote)
set theTagString to ""
set theName to ""
repeat with currentTag in currentNoteTags
set theName to name of currentTag
-- check to see if there is a space in the tag, and if so replace with a hyphen
set AppleScript's text item delimiters to " "
set theTextItems to text items of theName
set AppleScript's text item delimiters to "-"
set theName to theTextItems as string
set AppleScript's text item delimiters to {""}
set theTagString to ((theTagString & theName as string) & space) -- have to get the name attribute out of evernote's tags
end repeat
set theTagString to theTagString & importTag
mail_note(currentNoteTitle, currentNoteURL, theTagString) of me -- pass information to the mail handler
set exportedNotes to exportedNotes + 1 -- for reporting
assign tagForExportedNotes to currentNote
end if
end try
end repeat
finalMessage(missingURLNotes, exportedNotes) of me -- report back to user
end if
end tell
-- This routine is called for every note with an associated source URL. It creates and sends a single outgoing mail message in a format that Pinboard can understand.
on mail_note(title, theURL, theTagString) -- this subroutine formats the mail so that Pinboard can understand it
set theContent to ""
set theContent to (theURL & return & return & theTagString)
tell application "Mail"
set theMessage to make new outgoing message with properties {subject:title, content:theContent}
tell theMessage
make new to recipient at end of to recipients with properties {name:"Pinboard", address:pinboardEmail}
send theMessage
end tell
end tell
end mail_note
on confirmDialogHandler()
repeat
set whatToDo to confirmDialog()
if whatToDo is "Change Tags…" then
changeEvernoteTagDialog()
else
set nowWhat to (validatePinboardEmail() of me)
log nowWhat
if nowWhat is "Back" then
else
exit repeat
end if
end if
end repeat
end confirmDialogHandler
-- This routine presents the user with some information before exporting the notes. The user can check the email address that is about to be used, and has a chance to check or remove the tag added to bookmarks on import to pinboard.
on confirmDialog()
set numberOfNotes to count of notesToExport
set theWarning to "You're about to export " & numberOfNotes & " bookmark(s) to Pinboard, one per email. This may take some time and appear to crash Mail, but that's AppleScript for ya." & return & return & "The Pinboard email currently in use is shown below." & return & return & "Each successfully mailed note will be tagged with " & exportTag & " in Evernote. Notes skipped because they're missing a source URL will be tagged with " & missingURLTag & "." & return & return & "Each new bookmark in Pinboard will have the tag " & importTag & " added to its existing tags from Evernote."
set returnedItems to (display dialog theWarning default answer pinboardEmail with title "What's about to happen" buttons {"Cancel", "Change Tags…", "Export to Pinboard"} default button 3 cancel button 1) -- this is the initial dialog
set pinboardEmail to the text returned of returnedItems
set buttonPressed to the button returned of returnedItems
return buttonPressed
end confirmDialog
on changeEvernoteTagDialog()
set returnedItems to (display dialog "Change or remove tag to add to notes in Evernote that are successfully mailed:" default answer exportTag with title "Evernote tag" buttons {"Next tag…"} default button 1)
set exportTag to text returned of returnedItems
changeMissingURLTagDialog()
end changeEvernoteTagDialog
on changeMissingURLTagDialog()
set returnedItems to (display dialog "Change or remove tag to add to notes that were skipped because they had no source URL:" default answer missingURLTag with title "Missing URL tag" buttons {"Next tag…"} default button 1)
set missingURLTag to text returned of returnedItems
changeImportTagDialog()
end changeMissingURLTagDialog
on changeImportTagDialog()
set returnedItems to (display dialog "Change or remove tag added to the new bookmarks in Pinboard: (spaces between words will create multiple tags)" default answer importTag with title "Pinboard tag" buttons {"Done…"} default button 1)
set importTag to text returned of returnedItems
end changeImportTagDialog
-- This routine checks that the entered email contains @pinboard.in as a simple validation that you're not about to spam someone undeserving with lots of automated emails
on validatePinboardEmail()
set validationString to "@pinboard.in"
try
set valid to (offset of "@" in pinboardEmail)
if valid is 0 then
display alert "Not a valid email!" as critical buttons {"Back"} default button 1 message "The address " & pinboardEmail & " doesn't appear to be an email address: please check and try again!"
set response to "Back"
return response
else
set nextValid to (offset of validationString in pinboardEmail) -- check that the email contains the @pinboard.in address
if nextValid is 0 then
set alertMessage to "The address " & pinboardEmail & " doesn't appear to be valid for mailing bookmarks to Pinboard." & return & return & "Check your settings at pinboard.in to find the correct email address for your account."
set response to display alert "Valid Pinboard email?" as warning buttons {"Back", "Continue export"} default button 1 message alertMessage
set buttonResponse to button returned of response
return buttonResponse
end if
return "Valid"
end if
end try
end validatePinboardEmail
-- This presents a final dialog box to the user telling them what happened during export/import
on finalMessage(missingURLNotes, exportedNotes)
if exportedNotes is 0 then
set exportedMessage to "No bookmarks were mailed to Pinboard. " & missingURLNotes & " note(s) were skipped as they did not have an associated source URL and these notes were marked with the tag " & missingURLTag & " in Evernote."
else if exportedNotes is equal to (count of notesToExport) then
set exportedMessage to "The " & exportedNotes & " note(s) you selected were mailed to Pinboard. Notes in Evernote were all tagged with " & exportTag & " and the new bookmarks in Pinboard were tagged with " & importTag & "."
else
set exportedMessage to "A total of " & exportedNotes & " note(s) were mailed, tagged with " & exportTag & " in Evernote and " & importTag & " in Pinboard. " & return & return & missingURLNotes & " note(s) were skipped as they did not have a source URL and were tagged with " & missingURLTag & " in Evernote."
end if
set response to display alert "All done!" message exportedMessage buttons {"Go to Pinboard", "OK"} default button 2
if button returned of response is "Go to Pinboard" then
tell application "Safari"
open location "http://pinboard.in"
activate
end tell
end if
end finalMessage
@robertmeta
Copy link

robertmeta commented Jun 10, 2016

Just wanted to let anyone looking at this know -- as of this comment date -- this script still works like a champ on OS 10.11 /w Evernote 6.7.1 -- and out of the various applescripts I have tried, it is by far the fastest and most consistent was able to move 2500+ URLs with no issues. Terrific.

@dictions
Copy link

I can verify that this still works on Evernote version 6.10, OSX 10.12.14.

✊ 🎉

@WillPapper
Copy link

Thanks for the script! I also found another alternative in case anyone is looking. It's a Ruby script that takes in an Evernote .enex file and outputs a Pinboard .xml file that you can import via the Settings page. It's here: https://github.com/pglaz/shiny-octo-evernote-pinboard-instant-converter

(Not my script, but I can verify that it works as of April 2019, Evernote 7.9 and Ruby 2.3.7)

@jwfuller
Copy link

The script in the gist worked in May 2020, Evernote 7.14 OSX 10.15.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment