Hey Folks,
I usually scrape new MacScripter message links once (or more) per day from the new since last log-in page in Safari to a BBEdit document and then peruse them at my leisure. (I have a sort of pseudo-rss system that uses BBEdit and Safari for this.)
But sometimes there are 10 or less, and I just want to process them _now_ – so I wrote a script to scrape and open for Safari.
Then I thought I might as well adapt it for Chrome.
Both are appended.
These aren't very smart (in that they don't manage multiple messages in the same thread) – but I'll fix that in future – when I have a bigger message sample to work with.
------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2016/09/18 07:15 # dMod: 2016/09/18 07:30 # Appl: Safari # Task: MacScripter - Open New Messages in Tabs in Front Window # Libs: None # Osax: None # Tags: @Applescript, @Script, @Safari, @Open, @New, @Messages, @Tabs, @Front, @Window -------------------------------------------------------------------------------------------
set regexStr to "pid=" set linkList to safari_links(regexStr, "*", "href")
if linkList ≠ {} then tell application "Safari" set URL of front document to item 1 of linkList set linkList to rest of linkList if linkList ≠ {} then tell front window repeat with theLink in linkList make new tab at end of tabs with properties {URL:theLink} end repeat end tell end if end tell end if
------------------------------------------------------------------------------------------- --» HANDLERS ------------------------------------------------------------------------------------------- on safari_links(regexStr, tagName, tagType) set js 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_ js in document 1 if linkList = missing value then set linkList to {} on error set linkList to {} end try
return linkList
end safari_links -------------------------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------------------------------------------------------------------- # Auth: Christopher Stone # dCre: 2016/09/18 07:30 # dMod: 2016/09/18 07:41 # Appl: Google Chrome # Task: MacScripter - Open New Messages in Tabs in Front Window # Libs: None # Osax: None # Tags: @Applescript, @Script, @Google_Chrome, @MacScripter, @Open, @New, @Messages, @Tabs, @Front, @Window -------------------------------------------------------------------------------------------
set regexStr to "pid=" set linkList to chrome_links(regexStr, "*", "href")
if linkList ≠ {} then tell application "Google Chrome" tell front window set URL of active tab to item 1 of linkList set linkList to rest of linkList if linkList ≠ {} then repeat with theLink in linkList make new tab at end of tabs with properties {URL:theLink} end repeat end if end tell end tell end if
------------------------------------------------------------------------------------------- --» HANDLERS ------------------------------------------------------------------------------------------- on chrome_links(regexStr, tagName, tagType) set js 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;"
tell application "Google Chrome" tell front window tell active tab execute _javascript_ js end tell end tell end tell
end chrome_links
-------------------------------------------------------------------------------------------
|