www> The Cheats Lair> Blog

Contact: AIM: Mouse4537 Email: TravisB@eternallightstudios.com

May 11, 2004

iTunes iChat applescript

Have you noticed people on your buddy list with the now playing stuff on their status? Heres how:

-- the following strings precede the track info in iChat status.
-- these are Unicode strings
-- you can change them, if you like, just make sure
-- text is always inside ""
property message_prefix1 : «data utxt266B0020» -- BEAMED EIGHTH NOTES
property message_prefix2 : «data utxt29BF0020» -- CD (CIRCLED BULLET)
property message_prefix3 : «data utxt26220020» -- STREAM (RADIOACTIVE SIGN)
property message_prefix4 : «data utxt266B0020» -- spare not used yet, same as 1

-- this string is displayed when iTunes is not playing
-- you can change it, if you like, just make sure
-- text is always inside ""
property not_listening_message : "iTunes is off"

-- do not change these
property theT : null
property art : null
property nom : null
property cur_message : ""
global iTunes_is_running, ok_to_Idle, myMessage, message_prefix

on run
set ok_to_Idle to false
set iTunes_is_running to false
copy message_prefix1 to message_prefix -- 8ths
set e to my running_apps()
if e contains "iTunes" and e contains "iChat" then
set iTunes_is_running to true
tell me to poll_itunes()
else
if button returned of (display dialog "iTunes and/or iChat is not running at the moment. Stay running anyway?" buttons {"No - Quit Now", "OK - Stay Running"} default button 2 with icon 2) contains "Quit" then quit
end if
set ok_to_Idle to true
return 10
end run

-- refresh by tapping in the Dock
-- may use for preferences settings in future
on reopen
tell me to run
end reopen

on idle
if ok_to_Idle then
set e to my running_apps()
if e contains "iTunes" and e contains "iChat" then
set iTunes_is_running to true
tell application "iChat" to set cur_message to status message
tell me to poll_itunes()
else if e does not contain "iTunes" and e contains "iChat" then
set iTunes_is_running to false
tell application "iChat" to set status message to not_listening_message
end if
return 10
end if
end idle

to poll_itunes()
set ok_to_Idle to false


-- Remove or comment-out this "tell" block if you want iChat to display your...
tell application "iChat"
try
if status is not available then return
on error
return
end try
end tell
-- ...iTunes songs no matter what your "Away" or "Available" status is.


if iTunes_is_running then
tell application "iTunes"
try
if player state is playing then
set theNewT to current track
if theNewT is not theT or (nom is not theNewT's name or art is not theNewT's artist) or cur_message does not start with message_prefix then
copy theNewT to theT
tell me to fig_tags()
-- comment out the next line to skip truncate feature
tell me to truncate(nom, art)

tell me to do_ichat()
end if
else
tell application "iChat" to set status message to ¬
not_listening_message
end if
end try
end tell
end if
set ok_to_Idle to true
end poll_itunes

to fig_tags()
-- initialize; used as two parts of status message
set {nom, art} to {"", ""}

tell application "iTunes"
if class of theT is URL track then
copy message_prefix3 to message_prefix -- radioactive
tell theT
try
if name is not "" and name is not missing value then
set nom to name
else
set nom to "unknown"
end if
end try
end tell
-- if 4.1+ stream...
try
if (get current stream title) is not missing value then
set {art, nom} to my TextToList((get current stream title), " - ")
set art to " by " & art
end if
end try
else -- is file, cd, device, or other track
if class of theT is audio CD track then
copy message_prefix2 to message_prefix -- CD
else
copy message_prefix1 to message_prefix -- 8ths
end if

tell theT
try
if artist is not "" then
set art to (" by " & artist)
else
set art to ""
end if
end try
try
if name is not "" then
set nom to name
else
set nom to "unknown"
end if
end try
end tell
end if
end tell
set myMessage to (nom & art)
end fig_tags

to truncate(nom, art)
set lennom to (count nom)
set lenart to (count art)
set totlen to (lenart + lennom)
if totlen is greater than 40 then -- chop it down
if lennom > 19 then -- name is long
-- how much space from artist?
if lenart is less than or equal to 20 then
-- use difference for nom
set nom to (text 1 through (19 + (20 - lenart)) of nom) & "…"
else
set nom to (text 1 through 19 of nom) & "…"
set art to (text 1 through 19 of art) & "…"
end if
else
if lenart > 19 then -- name is long
-- how much space from nom?
if lennom is less than or equal to 20 then
-- use difference for art
set art to (text 1 through (19 + (20 - lennom)) of art) & "…"
else
set art to (text 1 through 19 of art) & "…"
set nom to (text 1 through 19 of nom) & "…"
end if
end if
end if
end if
set myMessage to (nom & art)
end truncate

to do_ichat()
tell application "iChat"
try
if status message does not end with myMessage then
set status message to message_prefix
set status message to (status message & myMessage)
end if
on error errMs
display dialog errMs
end try
end tell
end do_ichat

on running_apps()
tell application "System Events"
return (get name of every process)
end tell
end running_apps

on quit
set ok_to_Idle to false
if my running_apps() contains "iChat" then
tell application "iChat"
if status is idle then set status message to "Idle"
if status is available then set status message to "Available"
if status is away then set status message to "Away"
end tell
end if
continue quit
end quit

--============================================
on TextToList(theText, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theList to every text item of theText
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStr number errNum
end try
set AppleScript's text item delimiters to saveDelim
return (theList)
end TextToList

on ListToText(theList, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theText to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStr number errNum
end try
set AppleScript's text item delimiters to saveDelim
return (theText)
end ListToText


Copy it into Script Editor and click 'Compile'. Save it. Then open up users/(your user name)/libary/iTunes/Scripts/ If there isnt a Scripts folder, add it. Place your new applescript in there. When you are in iTunes, theres a small menu that looks like an applescript icon. Click it and scroll down to your script. It will start up iChat and change your status to whatever song you are playing. If you dont have a song playing, it will say 'not listening to iTunes' or something like that.

If it doesnt work, send me a message with the AIM name at the top. ;)

Posted by TheCheat at 05:23 PM | Comments (1)

May 07, 2004

RANT: Wooden Spoons

Who wants to eat stuff with spoons made out of wood. Splinters, bad taste all take away from the flavor of what your eating, lets call it Ice Cream. Ice Cream is supposed to taste like vanilla if your eating vanilla ice cream. But with wooden spoons, it tastes like wood! No Duh!

I hate having to get wooden spoons in the lunchlines. If you dont get wooden spoons, you have to pay 50 cents for a spork. Geeze!

Posted by TheCheat at 07:31 PM | Comments (0)

May 02, 2004

Leaky Tire Cat

My cat, Gizmo, sounds like a leaky tire. I look at him, HISS!! i walk past him HISS!! I lunge at him, HISS!!

Pictures in Exended BLOG


Cute?

WRONG!

Little Turd

Posted by TheCheat at 08:28 PM | Comments (1)

Rants (05/02/2004)

TIERED LUNCH TIMES
What the f*** is up with tiered lunch times? I mean, they have a semi-decent excuse. "Its to let the classes in the rear of the school get to lunch at the same time." Well, it doesnt take 5 minutes to walk 10 feet! My god! They must think were fat bastards that have to stop every foot to take a 30 second breather! DSMS is a screwed up school! They expect us to take all this 'your slow so were giving you, oh say, 5 minutes to get to lunch before 2 other classes get let out of their class rooms....

Then in another 5, 2 more get let loose and by that time you better get your fat a** down to the lunch room or we will give you lunch sac for loitering around in the friggin hall!' I know ive said this before but, MY GOD! Just let us out on one bell, if your in a class far from the lunch room, thats your fault for sigining up for the dang thing in the first place. Just have 1 minute from one bell to the next that way, if you want to get to lunch before the lunch lines get huge, then run your fat butt off!

That brings up another topic:
LUNCH LINES
They are way too long! We have 300+ students that dont bring their food from home because they dont have time or money, and the school is only letting 4 students through the lines at a time? Thats a sad way to feed kids. Lets see, 4 students goes into 300 75 times, thats 75 rounds of students. If each kid takes an average of 1 minute to get in, get their food and get out, then thats 75 minutes. Devide 75 by 60 and you get 1.25 hours. That leaves 5 minutes to spare. but most kids take longer in the lines than 1 minute. So, if you have 5 minutes to spare, and say the register explodes, your gonna have alot of hungry kids.

Posted by TheCheat at 05:55 PM | Comments (1)