Would you test the following scripts for me on the 10.12.5 beta?
They fail in the Safari Technology Preview (10.2) on macOS 10.12.3, and that is very, very bad for me.
Reports suggest the same failure on 10.12.4...
TIA.
------------------------------------------------------------------------------
# Test this one on a Google search page:
------------------------------------------------------------------------------
# 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)
end tell
------------------------------------------------------------------------------
# Test this one on any page with links:
------------------------------------------------------------------------------
set regexStr to ".*"
set linkList to safari_links(regexStr, "*", "href")
------------------------------------------------------------------------------
--ยป HANDLERS
------------------------------------------------------------------------------
on safari_links(regexStr, tagName, tagType)
set _javascript_CMD to "function in_array (array, item) {
for (var i=0; i < array.length; i++) {
if ( array[i] == item ) {
return true;}}
return false;}
var a_tags = document.getElementsByTagName('" & tagName & "');
var href_array = new Array();
var reg = new RegExp(/" & regexStr & "/i);
for (var i=0; i < a_tags.length; i++) {
var href = "" style="line-height: normal; font-family: Verdana;" class=""> & tagType & ";
if ( reg.test(href)) {
if ( !in_array(href_array, href)) {
href_array.push(href);}}}
href_array;
"
try
tell application "Safari" to set linkList to do _javascript_ _javascript_CMD in document 1
if linkList = missing value then set linkList to {}
on error
set linkList to {}
end try
return linkList
end safari_links
------------------------------------------------------------------------------