7. One Simple Package to Rule Them All

To have an easy to use interface, I've linked everything together in a package. To create a package that triggers a bash script that executes everything we use a little AppleScript. This AppleScript we compile as a package and then we add the bash script and all the binaries in it.

To provide for some interactivity with the user, a nice little application is used that gives a wide variety of dialogs to be called from the command line, CocoaDialog.

The final bash script that does everything is not so simple anymore as it used to be, but I think it's still readable enough to include here:

Code listing 7.1: generate.sh bash script to do it all

#!/bin/bash

if [ "${1}" ]; then
  musicXmlFile="$1"
else
  musicXmlFile=~/Music/iTunes/iTunes\ Music\ Library.xml
fi

export set WORKINGDIR=`dirname "$0"`
export set destinationDir=$2
export set destinationDirUrl=`"${WORKINGDIR}/urlencode.sh" "$2"`

"${WORKINGDIR}/xml" tr "${WORKINGDIR}/../xml/makeProperXml.xsl" \
	"$musicXmlFile" \
	> /tmp/mymusic$$.xml

"${WORKINGDIR}/xml" tr "${WORKINGDIR}/../xml/makeMainXml.xsl" \
    -s "destinationDir=$destinationDirUrl" \
    /tmp/mymusic$$.xml > /tmp/mymusic2$$.xml

OLDIDS=`"${WORKINGDIR}/xml" sel -T -t -m xmlLibrary/includeXml -v "concat(node(),' ')" /tmp/mymusic2$$.xml`

echo "<?xml version=\"1.0\"?>" > "${destinationDir}/mymusic.xml"
echo "<xmlLibrary xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> "${destinationDir}/mymusic.xml"

for oldit in $OLDIDS; do
    file="${oldit}.xml"
    PICTUREURL=`"${WORKINGDIR}/../bin/xml" sel -T -t -v /AlbumItem/Picture/PictureURL "${destinationDir}/${file}"`
    NEWID=`"${WORKINGDIR}/createId.command" "${destinationDir}/$file"`
    "${WORKINGDIR}/getPicture" "${PICTUREURL}" "${destinationDir}/${NEWID}-high"
    "${WORKINGDIR}/resizePicture" --dpi 60 "${destinationDir}/${NEWID}-high" "${destinationDir}/${NEWID}-low.png"
    "${WORKINGDIR}/xml" ed -u /AlbumItem/AlbumID -v "$NEWID" "${destinationDir}/$file" > "${destinationDir}/${NEWID}.xml"
    rm -f "${destinationDir}/$file"
    "${WORKINGDIR}/xml" tr --xinclude "${WORKINGDIR}/../../Resources/English.lproj/makeFinalXHtmlDetail.xsl" \
	"${destinationDir}/${NEWID}.xml" > "${destinationDir}/${NEWID}.html"
    echo "<xi:include href=\"${NEWID}.xml\" />" >> "${destinationDir}/mymusic.xml"
done

echo "</xmlLibrary>" >> "${destinationDir}/mymusic.xml"

# for every xml file, apply stylesheet to obtain corresponding html file

# for mymusic.xml file, apply main stylesheet to obtain index file

"${WORKINGDIR}/xml" tr --xinclude "${WORKINGDIR}/../../Resources/English.lproj/makeFinalXHtml.xsl" \
   "${destinationDir}/mymusic.xml" > "${destinationDir}/mymusic.html"

cp "${WORKINGDIR}/../../Resources/default.css" "${destinationDir}/default.css"

open "${destinationDir}/mymusic.html"

rm /tmp/mymusic$$.xml
rm /tmp/mymusic2$$.xml

line
Updated $LastChangedDate: 2004-11-18 23:41:16 +0100 (Thu, 18 Nov 2004) $
line
Kristof Van Landschoot
Author

line
Summary: Making one package is always nicer. Nicer to download, easier to use.
line
Copyright 2003-2004 Coin-C bvba. Questions, Comments, Corrections? Email cctunes@coin-c.com.