I suppose it’s fitting that my company forked over the money for me to attend MacWorld Expo this year so I could take the AppleScript Powertools class, and the first script I ever wrote is meant purely for screwing around.
I’m not sure how the community feels about posting goofy scripts, but my geeky coworkers and I have had fun this this one, so I figured I’d share it. When faced with deciding who will take care of a task that no one wants to do, the joke has been to roll for initiative. I thought it would be fun to make a script to automate the process. Essentially it uses iChat to send a roll for initiative with a value from 1 to 20, and also automatically reply with a roll when receiving one. I also created a version that will automatically reply with a number greater than the one received, but I’m keeping that one to myself.
Just put this script in the ~\Library\Scripts\iChat directory, set it to fire off in iChat for the Message Received, Message Sent, and Text Invitation alerts, then message your friends with “roll for ini” and let the madness ensue. It’s more fun if everyone does it.
(*
This 'waste of time' script automates a roll for initiative in iChat.
Essentially, if you send or receive the text "roll for ini", it will reply with "begin roll for initiative: #". The # is a value from 1 to 20. If you receive "begin roll for ini...", it will reply with "my roll for initiative: #". If everyone implements this same script, then it causes an instant begin and reply for the roll.
*)
-- We're using iChat, of course
using terms from application "iChat"
-- Receive chat invitation block
on received text invitation theMessage from theBuddy for theChat
accept theChat -- Automatically accept the chat
if theMessage begins with "roll for ini" then -- If receiving the text "roll for ini", reply with a "begin" roll
send rollTextWith("begin") to theChat
else if theMessage begins with "begin roll for ini" then -- if receiving a "begin roll for ini", reply with a "my" roll
send rollTextWith("my") to theChat
end if
end received text invitation
-- Receive message block
on message received theMessage from theBuddy for theChat
if theMessage begins with "roll for ini" then -- If receiving the text "roll for ini", reply with a "begin" roll
send rollTextWith("begin") to theChat
else if theMessage begins with "begin roll for ini" then -- if receiving a "begin roll for ini", reply with a "my" roll
send rollTextWith("my") to theChat
end if
end message received
-- Send message block
on message sent theMessage for theChat -- If sending the text "roll for ini", send a roll for initiative that starts with "begin"
if theMessage begins with "roll for ini" then
send rollTextWith("begin") to theChat
-- Return whitespace to 'cancel' the text that was originally sent
return " "
end if
end message sent
-- Generate a reply with theText at the start
-- The final result will start with theText, and end with "roll for initiative: #", where # is a value from 1 to 20.
on rollTextWith(theText)
return theText & " roll for initiative: " & (random number from 1 to 20)
end rollTextWith
end using terms from