Time for another quick tip! I know I removed the ones from before – Sorry; I’ve been changing my diary quite a bit, and considered it somewhat out of date. Besides, I have no idea if anyone even bothers reading this silly little journal of mine.
Assuming you have a bourne compliant shell, this will pick a random MP3 within a directory you specify, if you specify none, it will choose from the current directory (or subdirectories thereof):
#!/bin/sh
if [ ”$1x” == “x” ]
then
DIRLIST=”.”
else
DIRLIST=”$1”
fi
find $DIRLIST -type f -name \*.mp3 | sed -n $((1 + $RANDOM % `ls|wc -l`))p
If you name this “randfile.sh”, you can utilize as follows:
%open `/bin/sh /path/to/randfile.sh`
Myself, I made this an alias, so I can just type “randmp3”. As this uses ‘open’, it will follow the HFS creator code for whatever you have set for your audio files, such as Audion. A spiffy alternative to ‘open’ is ‘launch’, by Nicholas Riley, and can be directly swapped with ‘open’ above.
Note that this approach is rather suboptimal, as ‘find’ will recuse over your entire directory structure, a simpler approach would be:
ls $DIRLIST/*.mp3 | sed -n $((1 + $RANDOM % `ls|wc -l`))p
...but this doesn’t do any post checking for any funky ls settings if you’re running a non-standard ls (such as color-ls). You can grep that out if you need to. It’s your call, change for your needs. ;)