|
9. One Simple Package
The final bash script that does everything is, now that we've outlined
the techniques, a pretty straightforward bash script.
Code listing 9.1: generate.command bash script does it all |
#!/bin/bash
debug=1
if [ $debug -ne 0 ]; then
echo "0 [$0] 1 [$1] 2 [$2] 3 [$3] 4[$4]" > /tmp/debuginfo
fi
# get my location (don't worry about this one)
# this one is used by other scripts too
export set WORKINGDIR=`dirname "$0"`
# "/Users/kristof/Desktop/Library.xml" for instance
musicXmlFile="$1"
# "/Users/kristof/Desktop/New Folder" for instance
destinationDir="$2"
destinationDirUrl=`"${WORKINGDIR}/urlencode.sh" "$2"`
# makeFinalXHtml.xsl or makeListXHtml.xsl
styleSheet="$3"
"${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
# get list with old id's, the ones that were assigned on a starting with number one basis
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 mymusic.xml file, apply main stylesheet to obtain index file
"${WORKINGDIR}/xml" tr --xinclude "${WORKINGDIR}/../../Resources/English.lproj/${styleSheet}.xsl" \
"${destinationDir}/mymusic.xml" > "${destinationDir}/mymusic.html"
/bin/cp "${WORKINGDIR}/../../Resources/default.css" "${destinationDir}/default.css"
/usr/bin/open "${destinationDir}/mymusic.html"
if [ $debug -eq 0 ]; then
/bin/rm /tmp/mymusic$$.xml
/bin/rm /tmp/mymusic2$$.xml
fi
|
For to those that like it, having a command line script is nice. You can
use it for your scripting, without have to figure out what AppleEvents you
should signal an application using AppleScript. Those that have ever done
anything like this will appreciate to have a command line script ready to
trigger from the crontab.
And those that don't just use the package, which is just a GUI wrapper around
this script. You can fill in the arguments with a intuitive interface and
everything should work as expected.
If nothing goes wrong that is... feedback is still a bit underdeveloped at
the moment in the GUI.
|