Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add links from Mail to Safari Reading List
Add to Reading List
Script for Apple Mail to find http and https links in emails and add them to Safari's Reading List automatically.
Best practice: setup with "any recipient contains '+reading'". Actions "mark as read", "execute AppleScript", "delete message", "stop evaluating rules"
Created by Andreas Zeitler on 2012-10-07
Mac OS X Screencasts.
using terms from application "Mail"
set theURLs to {}
on perform mail action with messages theMessages
set theMessageCount to count of theMessages
repeat with theMessageIndex from 1 to theMessageCount
set theMessageContent to content of (item theMessageIndex of theMessages)
-- find URLs in messages
set cmd to "echo \"" & theMessageContent & "\" | egrep -o -e 'http[s]?://\\S+' | sed 's/[<>]//'"
set theURLs to do shell script cmd
-- make URLs a list
set theURLs to paragraphs of theURLs
-- add URLs to reading list
my addToReadingList(theURLs)
end repeat
end try
end perform mail action with messages
end using terms from
on addToReadingList(theURLs)
-- set your preferred browser. Use "Safari" or "WebKit"
set myBrowser to "WebKit"
using terms from application "Safari"
tell application myBrowser
repeat with theUrl in theURLs
add reading list item theUrl as string
end repeat
end tell
end using terms from
end addToReadingList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment