-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/03/29 04:44
# dMod: 2017/03/31 03:14
# Appl: Safari, System Events
# Task: Open the First Hit on a Google Search
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @System_Events, @Open, @First, @Hit, @Google, @Search
-------------------------------------------------------------------------------------------
set xpathStr to "//*[@class=\\'r\\']/a"
set jsCmdStr to "
var xpathResults = document.evaluate('" & xpathStr & "', document, null, 0, null),
nodeList = [],
oNode;
while (_oNode_ = xpathResults.iterateNext()) {
nodeList.push(oNode.href);
}
nodeList.join('\\n');
"
# Allow for the possibility that Safari has been hidden.
# When Safari is hidden it does 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_ jsCmdStr in front document)
end tell
-------------------------------------------------------------------------------------------
If it returns a string of links then I'm back in business and can safely update to 10.12.4.
TIA.