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: Skeeve on Aug 18, '05 02:24:16AM
Just to add a bit of information that migt be useful for you. If you want to find out whether or not some application, like iTunes in this example is running you can ommit one grep. Usually I see this:

ps x \
| grep /Applications/iTunes.app/Contents/MacOS/iTunes \
| grep -v grep
The last grep to filter out the grep off the result. I think it's much easier to do if you take advantage of character classes. (cite of man grep)

A list of characters enclosed by [ and ] matches any  single  character
in that list; if the first character of the list is the caret ^ then it
matches any character not  in  the  list.   For  example,  the  regular
expression  [0123456789]  matches any single digit.
So try this when your iTunes is running:

ps x | grep [/]Applications/iTunes.app/Contents/MacOS/iTunes
You see: The first slash is in a character class and so grep can't find itself because it does no longer contain "/Appli..." but "[/]Appli..." Next thing to note is that there is a thing like the "HERE"-document in *nix and so in OS X too. (cite of man bash but true for all shells I know of)

Here Documents
This  type  of  redirection  instructs the shell to read input from the
current source until a line containing  only  word  (with  no  trailing
blanks)  is seen.  All of the lines read up to that point are then used
as the standard input for a command.

The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

No parameter expansion, command substitution, arithmetic expansion,  or
pathname expansion is performed on word.  If any characters in word are
quoted, the delimiter is the result of quote removal on word,  and  the
lines  in the here-document are not expanded.  If word is unquoted, all
lines of the here-document are subjected to parameter  expansion,  com-
mand  substitution,  and arithmetic expansion.  In the latter case, the
character sequence \<newline> is ignored, and \ must be used  to  quote
the characters \, $, and `.
If you also know, that osascript can read from standard input if you supply "-" instead of a filename, we can put this all together like this:

#!/bin/sh
if ps x \
| grep [/]Applications/iTunes.app/Contents/MacOS/iTunes\ >/dev/null
then
        osascript - <<'OSASCRIPT'
        tell application "iTunes"
                set foo1 to name of current track
                set foo2 to player position
                set foo3 to duration of current track
                set foo4 to foo1 & " " & foo2 & "/" & foo3
        end tell
OSASCRIPT
fi
Just two last notes about the if-line: 1. the \ is there to make the following blank part of the string to search for 2. >/dev/null is there to suppress the output of grep. We are only interested in grep's return code.

[ Reply to This | # ]