Code/karaokeArchiver

From kJams Wiki
Jump to navigation Jump to search

A number of people have asked for a utility to automatically create zip files of their CD+G/MP3 file sets. I did too, so I decided to write my own. I made a BASH script that scans a list of files for files and zips them together. I wrapped it all up in an Automator workflow, so you can just stick in in ~/Library/Services/ and it will then be available via right click for any folder in the Finder. (In anticipation of the flood of Windows users, you'll have to cook something up in Python.) Here is the script:

for f in "$@"
do
	FILETYPE=`basename "$f"|cut -d"." -f2`
MP=mp3
CDG=cdg
	if ( [ "$FILETYPE" = "$MP" ] || [ "$FILETYPE" = "$CDG" ] );
	then
		FILEPATH=`dirname "$f"`"/"`basename "$f"|cut -d"." -f1`
		echo "$FILEPATH"
		echo "$f"
		zip -j -m "$FILEPATH" "$f";
	fi
done


The easiest way is simply to wrap it in an Automator workflow. Here is how I did it: Just launch automator and drag the appropriate actions from the library to the stage. First go to "files and folders" and drag "Get Selected Finder Items" onto the stage. Next, drag "Get Folder Contents", selecting "Repeat for each subfolder found" if desired. Next drag Rename Finder items, and change it to "change case," with "extension only" set to "lowercase." Finally switch from "Files & Folders" to "Utilities" and drag "Run Shell Script" over. Paste the above code into the appropriate field, and select "usr/bin/BASH" from the pop up menu. If you want you can also drag over "Show Growl Notification" and or "Speak Text" to add a little finesse!

Save as an application, or a Server plugin, or both, and you should be set.

There are two caveats: 1) SL has a bug (I think) that throws up an error if you do not run this from inside Automator (it runs fine inside) and 2) if you have mp3s without a matching CDG file, or vice versa, it will zip the single file by itself. There are ways around this, but I'll leave that to you all as an exercise! :)