public
Last active

Add links from Mail to Safari Reading List

  • Download Gist
Add to Reading List.applescript
AppleScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
(*
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. www.macosxscreencasts.com
*)
 
using terms from application "Mail"
set theURLs to {}
on perform mail action with messages theMessages
try
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.