Well, it’s about time I posted something.
Just for fun, I decided to port cowsay to AppleScript. It must be run via Terminal, using the following command:
osascript cowsay.scpt "Your message here"
Anywho, here’s the source:
on run argv
try
set messageLength to count items of (item 1 of argv)
cowsay((item 1 of argv), messageLength)
on error -- if no arguments were passed
set theMessage to "You didn't specify any arguments!"
set messageLength to (count items of theMessage)
cowsay(theMessage, messageLength)
end try
end run
on cowsay(theMessage, messageLength)
set line1 to " _"
repeat messageLength times
set line1 to line1 & "_"
end repeat
set line1 to line1 & "_
"
set line2 to "< " & theMessage & " >
"
set line3 to " -"
repeat messageLength times
set line3 to line3 & "-"
end repeat
set line3 to line3 & "-
"
set line4 to " \\ ^__^
"
set line5 to " \\ (oo)\\_______
"
set line6 to " (__)\\ )\\/\\
"
set line7 to " ||----w |
"
set line8 to " || ||
"
return line1 & line2 & line3 & line4 & line5 & line6 & line7 & line8
end cowsay
Some possible expansions include:
¢Allowing the user to specify whether or not to end the message with an exclamation point OR figuring out how to properly escape them so that they can be passed to the script without coming out as “!”
¢ Allowing the use of a custom .cows file from the original Cowsay
Any feedback or comments are appreciated.