It irritates me when I just want to get a link from Google and other places, but they bury the real URL in masses of their own obfuscated link.
I had a script that grabbed the unobfuscated URL from the status bar of previous versions of Safari, but Apple broke that with El Capitan.
Here's a new version that works with OSX 10.11.x.
The BBEdit handler can easily be adapted to TextWrangler.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/28 06:30
# dMod: 2015/10/28 06:47
# Appl: Safari, System Events, BBEdit
# Task: Grab the URL from under the cursor.
# Tags: @Applescript, @Script, @Safari, @BBEdit, @System_Events, @Grab, @URL
-------------------------------------------------------------------------------------------
set _url to missing value
tell application "System Events"
if quit delay ≠ 0 then set quit delay to 0
tell application process "Safari"
if static text of front window ≠ {} then
set _url to value of first static text of front window
else
error "No link under the cursor!"
end if
end tell
end tell
if _url ≠ missing value then
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"“", "”"}}
set _url to text item 2 of _url
set AppleScript's text item delimiters to oldTIDS
# set the clipboard to _url
sendTextToNamedBBEditDoc({docName:1, docText:(_url & return), appendToDoc:true})
end if
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on sendTextToNamedBBEditDoc(|record|) -- Record format: {docName:|name|, docText:|text|, appendToDoc:true}
set {|document|, |text|, appendToDoc} to {docName, docText, appendToDoc} of |record|
tell application "BBEdit"
if appendToDoc = false or appendToDoc = 0 then
set text of document |document| to |text|
else if appendToDoc = true or appendToDoc = "append" or appendToDoc = 1 then
tell document |document|
if contents of last character ≠ return then set |text| to return & |text|
set after its text to |text|
end tell
end if
end tell
end sendTextToNamedBBEditDoc
-------------------------------------------------------------------------------------------