For quite a while I’ve been meaning to post the collection of scripts I’ve written over the years. The majority were written to avoid mundane tasks that consumed way too much keyboard time keeping me from:
- fun computer related activities
- being social
- sleeping
- not being on a computer
I figure I might as well take advantage of computers while humans still have the upper hand. We should embrace the fact that they don’t yet have the ability to get bored, tired, lazy or understand the word “no”. In short, I like making computers my bitch, having them do my virtual chores and stiff them on their allowance come Sunday.
Below is the first of hopefully many dedicated to scripts that someone out there may find helpful/useful as either a final solution or starting point for a similar project:
I was going through some files on my old Powerbook G4 (that has been converted into a digital photo frame) and came across a script I wrote a few years back. It automates mp3 encoding and uploads the encoded mp3’s to an ftp.
I was sick of manually converting Harris’ biweekly practice recordings to mp3 and then uploading them so everyone could listen to the ideas kicked around each week. Manually, the process would take a good 20 minutes each time. Each practice session would be recorded and saved in a folder with a naming convention based on the current date (eg: 03-31-09). The script was setup to run after each practice night via a cron job. Set it and forget it. Just the way I like it.
The script was written in bash and was intended originally for use on OS X. I used lame to convert the aif files from Abelton to mp3. Once converted the mp3 are zipped and upload to a server ftp. I’ve marked up the script a bit to explain what’s going on.
#go to folder with current date
cd $HOME/Music/Ableton
cd `date ‘+%m-%d-%y*’`
cd Samples/Recorded#dump directory list to temp file and count lines for loop
ls -1 *.aif > convert.tmp
y=`cat convert.tmp | wc -l`
x=1
e=`date ‘+%m-%d-%y’`#declare loop to extract each line individually to pass on to lame
while test $x -le $y
do
z=`sed 1q convert.tmp`#call lame and append mp3 file name with date
/Applications/lame –replaygain-accurate –preset standard “$z” harrispractice-”$e”-”$x”.mp3
sed ‘1,1d’ convert.tmp > next.tmp
cat next.tmp > convert.tmp
x=`expr $x + 1`
done#clean up, move mp3s to dated directory and zip
rm convert.tmp
rm next.tmp
mkdir ~/Desktop/Practice/”$e”
mv *.mp3 ~/Desktop/Practice/”$e”
cd ~/Desktop/Practice
zip -r * *#upload zip
ftp ftp://username:password@ftpsite/uploaddirectory/ << EOFmput *.zip
a
quit
EOF#delete local zip and mp3s
rm -rf ~/Desktop/Practice/*
On a related note: Â Twilight Zone – The Obsolete Man