Categories
Scripts

Send preset messages automatically with Adium and AppleScript

After coming across this article today on Reddit, I decided to cook up a little AppleScript to accomplish the same task for us Mac users.

Disclaimer: I would never do this to my boss, so if any potential employers are out there scoping out my blog please know that it’s truly for entertainment purposes…

OK so here’s the script.

  • It will send all of the messages in a text file to whatever screen name you choose at defined or random intervals
  • Adium needs to be loaded and you need to be signed in
  • You need to create the text file and know its path. It expects the file to be in plain text and each message to be separated by a new line. I haven’t experimented with anything other than plain text and you could possibly have encoding issues and send some offensive message in Chinese.

Select all of the text below and copy it. Though it’s cut off on the sides it will still grab it all.

-- your Adium IM account name
set imAccnt to "YOURACCOUNTNAMEHERE"

-- screen name of target
set targetName to "TARGETSCREENNAMEHERE"

-- path of input file with messages separated by a newline
-- example: "/Users/JohnDoe/Desktop/messages.txt"
set filePath to "PATHTOFILEHERE"

-- set minimum amount of time to wait before sending messages in seconds
set lowerTime to 200
-- set maximum amount of time to wait before sending messages in seconds
set upperTime to 800

-- open file for input and set variable for text
set textFile to (open for access (POSIX file filePath))
set textInput to (read textFile for (get eof textFile))
close access textFile

-- make a list of messages from every new line in the text file
set messages to every paragraph of textInput

-- make our counter variable the number of how many messages we have
set counter to count messages

-- send messages to our target at different intervals until we're out
repeat with counter from 1 to counter
	-- add a little bit of randomness to the delay
	delay (random number from lowerTime to upperTime)
	-- tell Adium to send the current message to our target
	tell application "Adium"
		-- set our current message to whatever message we're at
		set currentmessage to item counter of messages
		-- start a new chat with the target
		tell account imAccnt to set savedChat to make new chat with contacts {contact targetName} with new chat window
		send savedChat message currentmessage
	end tell
end repeat