So see how would I use the the mdls command to validate it. Like would there be anyway to use the output of the query and use it in an if statement or a case statement?
What you seem to be missing is the bash syntax for using the output of a command as a value for other commands, or assigning command output to a shell variable. This is called
command substitution. You should read about it on the bash man page, by finding the Command Substitution section:
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/bash.1.html
Basically, `command` or $(command) runs the command (with parameters if given) then strips off any terminal newlines and puts the output in place of the command-substitution expression. You really need to read this on the man page, rather than me paraphrasing it. Note the first form uses back-quotes (grave accents), not single-quotes/apostrophes.
You also need to experiment with this on a manual command-line before adding it to a script. You can build up command-lines in any text editor, then copy and paste them into Terminal.app. This avoids having to retype lines manually.
For example, to assign the output of an mdls command to a variable:
Code:
someVar=`mdls -name kMDItemContentType "$FILE"`
If you echo "$someVar", it will contain the entire string output from the mdls command. You will have to parse this output further if you want only the value, because mdls generally outputs a distinctive header for the file-name, followed by name=value pairs for each metadata value.
You could do some parsing in the backquoted expression:
Code:
someVar=`mdls -name kMDItemContentType "$FILE" | grep kMDItemContentType `
You could use 'awk' to parse the output instead of grep, and this would permit a more precise output that only contained the value of kMDItemContentType. You might also use the -raw and -nullMarker options of mdls to produce more precise output. You should play with those first.
So now that the content-type value is in a variable, you can proceed to classify it as image, text, or spreadsheet. There are any number of ways to do that. A switch statement is one way, which is relatively straightforward to understand and code.
Choosing a good classifying approach depends on how flexible the classifying has to be. Since it's a homework assignment, it probably doesn't need a lot of flexibility, so I'd go with 'switch' unless or until it proves to be unwieldy. If this were an actual IT program, then separating the classification data (i.e. the mapping of mdls output values to file-class) from the shell-script might be useful, so it wouldn't be necessary to edit a shell-script every time a classification changes.
You might also look at other useful mdls values, such as kMDItemContentTypeTree. You can see their values by applying mdls to sample classifiable files, and you can understand more about what each value means by reading the Spotlight Metadata docs. You can also try the output from the 'file' command and see if it's any easier to parse or classify.