I’m having both success and failures with the “For each item in a collection” when used with a Finder selection and then trying to use a shell script.
Example 1, and this one works: For each item in a collection, set variable = FullFilePath, based on The Finder’s selection, then execute: shell script of type text script, where the script is just this:
gzip -d -k $KMVAR_FullFilePath
That works exactly as I planned: I select a number of .gz files, call the macro, and they all expand.
But I wanted to modify this to handle files with different compression, i.e. I could select both .zip and .gz files, and decompress them in one pass. I wrote and tested a shell script, and it’s working fine in the shell. But the way I wrote it, I was pretty sure it wouldn’t work in KM - I create an array of filenames based on what’s passed on the command line, i.e. “uncompress *” grabs all the filenames in the directory, adds them to an array, then processes each in a ‘for’ loop.
For KM, which (I believe) runs the program over and over, once for each match, i wrote a much simpler version that just takes the first parameter and runs that through a case statement to figure out how to expand. It looks like this:
#!/bin/bash
OLDIFS=$IFS
IFS=$'\n'
echo $1
(for debugging)
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.rar) rar x $1 ;; # 'rar' must to be installed
*.jar) jar -xvf $1 ;; # 'jdk' must to be installed
*) echo "'$1' cannot be extracted via extract()" ;;
esac
IFS=$OLDIFS`
When I test this in Terminal, it works fine: Whatever file I indicate will be decompressed. in KM, I set this one up as “Execute script file,” since it’s a multi-line thing. I set it up like this:
/path/to/simple/script $KMVAR_FullFilePath
If I run that version, I get Execute Shell Script Exception as the only output. So then I tried without specifying the variable, and I get an error indicating that there’s no string value passed to the script.
What (obvious, I’m sure) thing am I missing here? I’ve read the help, the wiki, searched the net … but I’m stumped.
thanks;
-rob.