Skip to content

Instantly share code, notes, and snippets.

@zmwangx
Created February 2, 2014 07:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmwangx/8764383 to your computer and use it in GitHub Desktop.
Save zmwangx/8764383 to your computer and use it in GitHub Desktop.
AppleScript for saving URL to Safari reading list.
set theUrl to do shell script "pbpaste | grep -o -E \"\\b(https?|ftp|file)://[-A-z0-9+&@#/%?=~_|.;]*[A-z0-9+&@#/%=~_|]\" | head -1"
if theUrl = "" then
set html to do shell script "osascript -e '«class HTML» of (the clipboard as record)' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))'"
set theUrl to do shell script "echo " & quoted form of html & " | grep -o -E \"\\b(https?|ftp|file)://[-A-z0-9+&@#/%?=~_|.;]*[A-z0-9+&@#/%=~_|]\" | head -1"
end if
using terms from application "Safari"
tell application "Safari"
add reading list item theUrl as string
end tell
end using terms from
return theUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment