• 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
Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari


  • Subject: Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 30 Mar 2017 22:13:56 -0500

Hey Folks,

Can someone confirm that this script returns a list of links from a Google Search page in Safari on macOS 10.12.4?

TIA.

--
Best Regards,
Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/29 04:44
# dMod: 2017/03/29 04:44 
# Appl: Safari, System Events
# Task: Extract Links from a Google Search.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @System_Events, @Extract, @Links, @URLs, @Google, @Search
------------------------------------------------------------------------------

set xpathStr to "//*[@class=\\'r\\']/a"
set strJS to "

var xpathResults = document.evaluate('" & xpathStr & "', document, null, 0, null),
  nodeList = [],
  oNode;

while (_oNode_ = xpathResults.iterateNext()) {
  nodeList.push(oNode.href);
}

nodeList;

"

# Allow for the possibility that Safari has been hidden.
# When Safari is hidden it does NOT correctly discern window 1.
tell application "System Events"
    tell application process "Safari"
        if its visible is false then set its visible to true
    end tell
end tell

tell application "Safari"
    set linkList to (do _javascript_ strJS in front document)

    

    if linkList ≠ "" then
        return linkList
    else
        error "No links were found!"
    end if

    

end tell

------------------------------------------------------------------------------

 _______________________________________________
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

  • Follow-Ups:
    • Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
      • From: Steve Mills <email@hidden>
References: 
 >Sierra 10.12.4 and JavaScript by AppleEvents in Safari (From: Christopher Stone <email@hidden>)
 >Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari (From: Takaaki Naganoya <email@hidden>)
 >Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: range of integers?
  • Next by Date: Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
  • Previous by thread: Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
  • Next by thread: Re: Sierra 10.12.4 and JavaScript by AppleEvents in Safari
  • Index(es):
    • Date
    • Thread