Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'iTunes, the menu bar, unicode, and GeekTool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
iTunes, the menu bar, unicode, and GeekTool
Authored by: alys on Jul 08, '04 01:47:14AM
What a great idea!
Here's my version of the script, which works basically the same way, but which contains more track information, allows me to easily add or remove that information from the display (by editing the second last line of the script), and adds a bit of punctuation to separate the pieces of information. The code that formats the rating as asterisks could undoubtably be improved, but I didn't think it was really worth the effort of learning the right AppleScript syntax. :) Note that this script still has the problem of starting iTunes if it's not already running, so you'll need to wrap it in shell script as reported in other comments, if you don't normally have iTunes running all the time (alternatively, in GeekTool, put the script in a particular group and only use that group when you're playing music).

tell application "iTunes"
    -- This script extracts information about the track currently running in iTunes, and then
    -- formats it for one-line display (e.g., using GeekTool).
    -- See http://www.macosxhints.com/article.php?story=2004070301135736 for a
    -- detailed description of a similar script that gave me the idea for this one.

    -- this spacer determines how many spaces are between some of the items in the display:
    set spacer to "     "

    -- get some simple information and add spaces and punctuation:
    set myName to name of current track & "; "
    set myArtist to artist of current track
    set myGenre to spacer & "(" & genre of current track & ")"
    set myGrouping to spacer & "{" & grouping of current track & "}"

    -- if the track is in an album, then put a dash before the album name (to separate
    -- it from the information that will be printed before the album):
    set myAlbum to album of current track
    if myAlbum is not "" then
        set myAlbum to " - " & myAlbum
    end if

    -- get the rating, or a message if there is no rating:
    set myRating to round ((rating of current track) / 20)
    if myRating is 1 then
        set myRating to "*"
    else if myRating is 2 then
        set myRating to "**"
    else if myRating is 3 then
        set myRating to "***"
    else if myRating is 4 then
        set myRating to "****"
    else if myRating is 5 then
        set myRating to "*****"
    else
        set myRating to "NO RATING"
    end if
    set myRating to spacer & myRating

    -- get the current position of the track and calculate how far through
    -- the track we are, as a percentage:
    set myPosition to player position
    set myDuration to duration of current track
    set myPercent to spacer & (round (myPosition / myDuration * 100)) & "%"

    -- this final line determines which pieces of information are displayed:
    set output to myName & myArtist & myAlbum & myPercent & myRating & myGrouping
end tell



[ Reply to This | # ]
iTunes, the menu bar, unicode, and GeekTool
Authored by: Neil Gall on Jul 08, '04 05:16:52AM
I created a general purpose shell script which only executes the applescript if the appropriate application is running:

#!/bin/sh
app=$1
scpt=$2
if [[ -n "`ps -x | grep /Applications/${app}.app | grep -v grep`" ]]; then
  osascript $scpt | iconv -f utf-8 -t ucs-2-internal
fi
Then all my GeekTool shell commands look like

~/Scripts/do_script_if_app_running iTunes ~/Scripts/get_current_itunes_track.scpt

~/Scripts/do_script_if_app_running Mail ~/Scripts/check_mail.scpt
etc.

[ Reply to This | # ]
iTunes, the menu bar, unicode, and GeekTool
Authored by: alys on Jul 17, '04 11:42:09PM
That's useful! Thanks!
If you change this line:
if [[ -n "`ps -x | grep /Applications/${app}.app | grep -v grep`" ]]; then
to this:
if [[ -n "`ps -x | grep -i /Applications/.*${app}.app | grep -v grep`" ]]; then
then you don't need to type the application name with the correct upper- and lower-case letters (the -i switch to grep does a case-insensitive search), and you can specify applications that exist in subdirectories under the Applications directory (.* handles that). An unfortunate side effect of the latter change is that if you have applications called (for example) MyBooks.app and Books.app (i.e., two or more applications ending with the same word), then entering "Books" as the application name might launch the wrong application. This isn't a problem for me (at the moment!) but bear that in mind if you add '.*' to your code.

[ Reply to This | # ]
iTunes, the menu bar, unicode, and GeekTool
Authored by: webbix on Jul 21, '04 05:12:01PM
Thanks for the script. With that and another hint on checking for iTunes process I got mine running. I deployed slightly different as I place mine just below the menu bar as I have other data there and no Cinema display.

I did make a few changes the most important of which was to change the percent reading to a rudimentary progress bar. Just easier for me to visualize. Here is the code I subsittuted (also change the stars to take less room by subbing 1*, 2*, etc.):


	-- get the current position of the track and calculate how far through
	-- the track we are, as a percentage:
	set myPosition to player position
	set myDuration to duration of current track
	set myPercent to (round (myPosition / myDuration * 100))
	if myPercent < 10 then
		set myPercent to "]:::::::::"
	else if myPercent < 20 then
		set myPercent to ":]::::::::"
	else if myPercent < 30 then
		set myPercent to "::]:::::::"
	else if myPercent < 40 then
		set myPercent to ":::]::::::"
	else if myPercent < 50 then
		set myPercent to "::::]:::::"
	else if myPercent < 60 then
		set myPercent to ":::::]::::"
	else if myPercent < 70 then
		set myPercent to "::::::]:::"
	else if myPercent < 80 then
		set myPercent to ":::::::]::"
	else if myPercent < 90 then
		set myPercent to "::::::::]:"
	else
		set myPercent to ":::::::::]"
	end if
	set myPercent to spacer & myPercent

Thanks again for the original script!

[ Reply to This | # ]