I want to create a service using Automator to run a shell script on all files in a folder, say delete all log files. What I have done is
- Created a new service in automator.
- Added a "Run Shell Script" action. I have change this to 'pwd' for now.
- Selected "Service receives selected folders".
- Tried to run it, but get a message. "To test this service within Automator, add the "Get Specified Finder Items" action to the beginning of your workflow. Remove or disable the action before running the workflow outside of Automator.
- OK. So I add "Get Specified Finder Items". Added a 'test' directory to the list of items.
Now, when I run the script, the results window prints out my home directory.
Elsewhere, I have read that I maybe need to add
cd "$1"
to the beginning of my script. I did that but it still prints my home directory. How do I get this thing to print the directory I have selected in "Get Specified Finder Items?"
Edited to Add
Here is a screen shot of a script that works.
Here is a screen shot os a script that doesn't work.
The usual way I would deal with the "no match found : *.log" error would be to redirect error output to null. Replacing the "rm" line by
find . -name "*.log" -print0 | xargs -0 rm -rf
Does work though. This seems more difficult than it should be.