This script returns the users that are online on MacScripter in a list. Enjoy!
property userList : {}
property curUsers : {}
property userIDs : {}
(* Comments are a big part of other people's lives. Not mine. Yet I will include them anyway. :) *)
--comments will be placed BEFORE the action :)
set curUsers to {}
set userIDs to {}
--check the users (and do everything else)
checkUsers()
on getCurrentUsers()
--get the HTML code of MacScripter
try
set theContents to (do shell script "curl " & "\"http://www.macscripter.net/\"")
log result
on error
doQuit()
end try
--make sure its a string
set theContents to theContents as string
--get the online lsit
searchAndReplaceString_stringToSearchAndReplace_theSearchString(theContents, "<dt><strong>Online: </strong></dt>")
set the2 to item 2 of result as string
log result
--get the online list
searchAndReplaceString_stringToSearchAndReplace_theSearchString(the2, "</dl>")
set the1 to item 1 of result
log result
--and finally get the online list
searchAndReplaceString_stringToSearchAndReplace_theSearchString(the1, ">")
set theNList to result
set theNum to 0
set otherNum to 0
set almostNameList to {}
set gettingID to {}
--The items that are the user names are the third item, and then every fourth item from there
repeat with x from 1 to count theNList
if x = 2 then
set gettingID's end to item x of theNList
set otherNum to x
else if x = 3 then
set almostNameList's end to item x of theNList
log result
set theNum to x
else if x = theNum + 4 then
set almostNameList's end to item x of theNList
log result
set theNum to x
else if x = otherNum + 4 then
set gettingID's end to item x of theNList
set otherNum to x
end if
end repeat
log "Bubbles"
set IDList to sortID(gettingID)
set urlList to getID(IDList)
set userIDs to urlList
set sortNameList to {}
--now we need to add the finishing touches to our list
repeat with x from 1 to count almostNameList
searchAndReplaceString_stringToSearchAndReplace_theSearchString((item x of almostNameList), "<")
set sortNameList's end to item 1 of result
log result
end repeat
--set the list of curent users
set curUsers to sortNameList
return sortNameList
end getCurrentUsers
on searchAndReplaceString_stringToSearchAndReplace_theSearchString(stringToSearchAndReplace, theSearchString)
set returnString to stringToSearchAndReplace
set oldASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to theSearchString
set tempString to text items of stringToSearchAndReplace
--set AppleScript's text item delimiters to theReplaceString
set returnString to tempString
set AppleScript's text item delimiters to oldASTID
return returnString
end searchAndReplaceString_stringToSearchAndReplace_theSearchString
on checkUsers()
try
--get the list of users that were in last check
set tempList to userList
--get the current users
set userList to getCurrentUsers()
--if users left or joined then:
if tempList is not equal to userList then doesNotEqual(tempList)
--else jsut display who's online:
if tempList is equal to userList then set p to (choose from list curUsers with prompt "These are the users that are currently online." & return & return & "Select one to go to their ID page." with empty selection allowed) as string
if p is not equal to "false" then openID(p, tempList)
end try
end checkUsers
on doesNotEqual(temp)
try
set li to {}
set li2 to {}
--check for users
if temp is not equal to {} then
repeat with x from 1 to count temp
if item x of temp is not in userList then set end of li to item x of temp
end repeat
end if
repeat with x from 1 to count userList
if item x of userList is not in temp then set end of li2 to item x of userList
end repeat
--show the users
if li is not equal to {} then
choose from list li with prompt "These are the users who left since last check:" with empty selection allowed
end if
if li2 is not equal to {} then
choose from list li2 with prompt "These are the users who joined since last check:" with empty selection allowed
end if
set p to (choose from list curUsers with prompt "These are the users that are currently online." & return & return & "Select one to go to their ID page." with empty selection allowed) as string
if p is not equal to "false" then openID(p, curUsers)
end try
end doesNotEqual
on doQuit()
display dialog "Hmmm. You appear to not be connected to the internet, something vital for this app." buttons "OK" default button 1
quit
end doQuit
on sortID(theList)
set oList to {}
repeat with x from 1 to count theList
searchAndReplaceString_stringToSearchAndReplace_theSearchString((item x of theList as string), "<a href=\"")
set itm to item 2 of result
set oList's end to itm
end repeat
set theList to {}
repeat with x from 1 to count oList
searchAndReplaceString_stringToSearchAndReplace_theSearchString((item x of oList as string), "\"")
set itm to item 1 of result
set theList's end to itm
end repeat
return theList
end sortID
on getID(theList)
repeat with x from 1 to count theList
set tempi to item x of theList
set tempoi to "[url=http://www.macscripter.net/]www.macscripter.net/[/url]"
set tempoi2 to tempoi & tempi as string
set item x of theList to tempoi2
end repeat
return theList
end getID
on openID(pp, tempList)
repeat with x from 1 to count tempList
if item x of theList is pp then set theNum to x
end repeat
set theItem to item theNum of userIDs
tell application "Safari" to open location theItem
end openID
What was edited?
The script was redone once again so that when the choose from list command shows the current users you can select one to go to their account page on MacScripter.
And once again, I’m sure there’s a lot that could be changed to make the code shorter and more elegant, but right now it works and i’m happy with that.