Adding this variable at the top to my shell script allows me parse the files in a subfolder:
- Code: Select all
path=`dirname "$1"/sub_dir`
In Terminal I can run:
- Code: Select all
for i in "$path"/*.png; ${binaries}/mogrify -resize 640x800\> "$path"/*.png
I haven't found a way to make Hazel understand the "for" command and since it targets each file anyway I can write:
- Code: Select all
/usr/local/bin/mogrify -resize 640x800\> "$path"/*.png
Using "for" would give me more flexibility. So far I could work around it, but now I'm facing a problem when trying to rename files – more specific: making them lowercase and replacing spaces with dashes.
I have to do this because some of the shell scripts won't accept files with spaces in their name. "for" dealt with this beautifully in Terminal, but I guess for Hazel I have to rename them.
This works in Terminal for one part of what I want (the elimination of spaces):
- Code: Select all
for f in *; do mv "$f" "$(echo $f | sed 's/ /-/g')"; done
What I tried so far is:
- Code: Select all
mv "$path"/* | sed 's/ /*/g'
- Code: Select all
mv "$path"/* "$(echo $path | sed 's/ /-/g')"
I try to keep it to one rule and not create additional an additional "Run Rules On Folder Content" - in addition I simply want to understand how I can work more with Hazel and shell scripts.
I learned a lot in last week when setting up a (at least for me) complex set of rules which rely heavily on shell scripts. This forum gave me many clues and I found the posts from a_freyer very helpful. I'm eager to post about it, but for now I need this last puzzle solved. Any help is appreciated.
Update:
I found another script which I tried to modify to work with Hazel - also with no success:
- Code: Select all
#!/bin/bash
FILES=/path/to/dir/*
for f in $FILES
do
new_file=`echo $f|sed "s/ /-/g"`
if [ "$f" != "$new_file" ]
then
mv "$f" "$new_file"
fi
done
exit 0