Live Discussion?

So this script will display a random SD Help page every time it’s run. (The first time it runs it takes a bit longer to gather the URLs, after that it goes pretty quickly.)

It’s up to you to decide how to make it run every day/hour/minute.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property SDHelpURLs : {}
tell application "System Events" to set helpFileURL to (URL of (path to resource "toc.html" in bundle (path to application id "com.latenightsw.ScriptDebugger6") in directory "sd6help"))
set AppleScript's text item delimiters to {"toc.html"}
set helpFileRoot to text item 1 of helpFileURL
tell application "Safari" to set myWindow to make new document at beginning
if SDHelpURLs = {} then
   tell application "Safari"
      set URL of document 1 to helpFileURL
      delay 10
      set docSource to source of document 1
   end tell
   set SDHelpURLs to my findParsContaining:"<a href=\"indexfolder/" inString:docSource matchCase:false
end if
set thisPage to some item of SDHelpURLs
set AppleScript's text item delimiters to {"<a href=\"", "\">"}
set pageURL to text item 2 of thisPage
set pageURL to helpFileRoot & pageURL
tell application "Safari"
   set URL of document 1 to pageURL
end tell

on findParsContaining:findString inString:stringToSearch matchCase:caseFlag
   set stringToSearch to current application's NSString's stringWithString:stringToSearch
   -- escape pattern, in case it contains characters that have special meaning in patterns
   set escString to current application's NSRegularExpression's escapedPatternForString:findString
   if caseFlag then
      set theOptions to current application's NSRegularExpressionAnchorsMatchLines
   else
      set theOptions to (current application's NSRegularExpressionAnchorsMatchLines) + (get current application's NSRegularExpressionCaseInsensitive)
   end if
   set theRegex to current application's NSRegularExpression's regularExpressionWithPattern:("^.*" & escString & ".*$") options:theOptions |error|:(missing value)
   set theMatches to theRegex's matchesInString:stringToSearch options:0 range:{0, stringToSearch's |length|()}
   set theResults to {}
   repeat with aMatch in theMatches
      set end of theResults to (stringToSearch's substringWithRange:(aMatch's range())) as text
   end repeat
   return theResults
end findParsContaining:inString:matchCase:


1 Like