Tell a Joke
Posted: Fri Jun 29, 2012 4:09 pm
Here's a rather hodgepodge script that will speak a random joke.
They seem to all over the place from kids school yard, to something Chris Rock may tell.
I'm no coder, but it does seem to work ok. Just mod the folder and file name to taste.
Carl
They seem to all over the place from kids school yard, to something Chris Rock may tell.
- Code: Select all
set TID to AppleScript's text item delimiters
set FolderLocdo to quoted form of (POSIX path of (path to desktop) & "RSS" as text)
do shell script "mkdir -p " & FolderLocdo
set xxx to do shell script "curl http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Fwww.jokesareawesome.com%2Frss%2Frandom%2F%22&format=json&callback=cbfunc"
set theString to xxx
set AppleScript's text item delimiters to "<br />"
set xxx to text items of theString
set AppleScript's text item delimiters to {" "}
set xxx to xxx as text
set AppleScript's text item delimiters to "[CDATA["
set xxx to text items 3 thru -1 of xxx
set AppleScript's text item delimiters to {""}
set xxx to xxx as text
set AppleScript's text item delimiters to "]]>"
set xxx to text item 1 of xxx
set AppleScript's text item delimiters to TID
do shell script "echo " & quoted form of xxx & " > " & FolderLocdo & "/Joke.txt"
set sourceFolder to (path to desktop as text) & "RSS:"
set plainText to "Here's a joke for you. " & (read file (sourceFolder & "Joke.txt"))
say plainText
I'm no coder, but it does seem to work ok. Just mod the folder and file name to taste.
Carl