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


Click here to return to the 'Controlling iTunes from the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Controlling iTunes from the Terminal
Authored by: andrewgwhite on Jun 08, '03 04:49:16PM

I found that issuing 'itunes vol up' or 'vol down' would cause the script to barf when it hit 'if [ $2 -gt 0 ]; then', since that expression is testing for an integer. My fix, nasty as all get out probably, was to rewrite the case for vol thusly:

"vol" ) echo "Changing iTunes volume level.";
vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
if [ $2 = "up" ]; then
newvol=$(( vol+10 ));
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
break ;
fi

if [ $2 = "down" ]; then
newvol=$(( vol-10 ));
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
break ;
fi

if [ $2 -gt 0 ]; then
newvol=$2;
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
break ;
fi
break ;;

No one else has reported this issue, but if they stumble on it, I hope this helps. Also, if anyone has any ideas on how to do this a little more cleanly, please give me a shout.

Cheers,
a.



[ Reply to This | # ]
Controlling iTunes from the Terminal
Authored by: linky on Apr 24, '04 05:22:38PM
All you need to do is make this change to the offending line (line 80, the way I saved it:)
if [ $(($2)) -gt 0 ]; then
The bash manpage will tell you the $((...)) operator forces arithmetic expansion, which eliminates the comparison between a string and an integer.

[ Reply to This | # ]
Controlling iTunes from the Terminal
Authored by: teahaile on Aug 30, '06 06:26:08AM
the following makes more sense to me, logically:
            "vol"    ) echo "Changing iTunes volume level."
;
            if [ $($2) ]; then
                vol=`osascript -e 'tell application "iTunes
" to sound volume as integer'`;
                if [ $2 = "up" ]; then
                    newvol=$(( vol+10 ));

                elif [ $2 = "down" ]; then
                    newvol=$(( vol-10 ));

                elif [ $2 -gt 0 ]; then
                    newvol=$2;
                fi

                osascript -e "tell application "iTunes" t
o set sound volume to $newvol";
            fi


[ Reply to This | # ]
Controlling iTunes from the Terminal (last post was ERROR)
Authored by: teahaile on Aug 30, '06 06:47:22AM
last entry was an error on my part....i meant to suggest the following:
            "vol"    ) echo "Changing iTunes volume level."
;
            if [ -z $2 ]; then
                break;
            fi
                vol=`osascript -e 'tell application "iTunes
" to sound volume as integer'`;
                if [ $2 = "up" ]; then
                    newvol=$(( vol+10 ));

                elif [ $2 = "down" ]; then
                    newvol=$(( vol-10 ));

                elif [ $2 -gt 0 ]; then
                    newvol=$2;
                fi

                osascript -e "tell application "iTunes" t
o set sound volume to $newvol";

            break ;;


[ Reply to This | # ]