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: 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 | # ]