• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Get URL From Under Cursor in OSX 10.11.x Safari
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get URL From Under Cursor in OSX 10.11.x Safari


  • Subject: Get URL From Under Cursor in OSX 10.11.x Safari
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 28 Oct 2015 07:05:34 -0500

Hey Folks,

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 need to send someone the direct link form this:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB4QFjAAahUKEwjIv-6XhOXIAhVDVj4KHUmMBzo&url="">

What I really want is this:

https://applescriptlibrary.files.wordpress.com/2013/11/excel-2004-applescript-reference.pdf

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.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# 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
-------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: PDF Search
  • Next by Date: Re: Loss of formatting preferences
  • Previous by thread: Re: Visible on OSX 10.11.1
  • Next by thread: Wan IP Retrieval No Longer Works For Me Under OS X 10.11
  • Index(es):
    • Date
    • Thread