MacScripter: Search Topics by indicated KeyWords

Following script will find programatically all MacScripter topics which contain tell application “BBEdit” keyword.

I personally find this type of search the most useful (for myself), but if you want, it’s easy to add a forum search, a sorting method, etc. (see the structure of the searchURL variable).


property login : "KniazidisR" -- set here your login name
property |password| : "myPassword" -- set here your password
property searchExpression : "tell application \"BBEdit\"" -- set here search expression

-- login to MacScripter
my loginToMacScripter(login, |password|)

-- search MacScripter Topics by indicated serach expression (by keywords)
set searchExpression to my encodeSearchExpression(searchExpression)
set searchURL to "https://macscripter.net/search.php?action=search&keywords=" & searchExpression & "&author=&forum=-1&sort_by=5&sort_dir=DESC&show_as=topics&search=Submit"
my waitSafariWebPageLoading(10) -- wait maximum 10 seconds
open location (searchURL)


on loginToMacScripter(login, |password|)
	tell application "Safari"
		activate
		open location ("http://macscripter.net/login.php")
		my waitSafariWebPageLoading(10) -- wait maximum 10 seconds
		do JavaScript "login.req_username.value = \"" & login & "\"" in document 1
		do JavaScript "login.req_password.value = \"" & |password| & "\"" in document 1
		do JavaScript "login.login.click()" in document 1
	end tell
end loginToMacScripter


on encodeSearchExpression(searchExpression)
	set ATID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to space
	set searchExpression to text items of searchExpression
	set AppleScript's text item delimiters to "+"
	set searchExpression to searchExpression as text
	set AppleScript's text item delimiters to "\""
	set searchExpression to text items of searchExpression
	set AppleScript's text item delimiters to "%22"
	set searchExpression to searchExpression as text
	set AppleScript's text item delimiters to ATID
	return searchExpression
end encodeSearchExpression


on waitSafariWebPageLoading(loadingWaitMaximumSeconds as integer)
	set lineChangingChars to {linefeed, return, character id 11, character id 12, character id 133, character id 8232, character id 8233}
	set {ATID, htmlEnding} to {AppleScript's text item delimiters, ""}
	tell application "Safari"
		repeat 100 * loadingWaitMaximumSeconds times
			delay 0.1
			set AppleScript's text item delimiters to {"<", ">"}
			try
				copy text item -2 of (get source of front document) to htmlEnding
			end try
			set AppleScript's text item delimiters to lineChangingChars
			set htmlEnding to text items of htmlEnding
			set AppleScript's text item delimiters to ""
			set htmlEnding to "<" & htmlEnding & ">"
			if htmlEnding is "</html>" then exit repeat
		end repeat
	end tell
	set AppleScript's text item delimiters to ATID
	if htmlEnding is "</html>" then return true
	display notification "The webpage loading failed"
	return false
end waitSafariWebPageLoading
1 Like