I'm making an automator service, and the first part takes files and RARs them using a bash script
So in Automator, I have a Get Specified Finder Items action to test the workflow, and then the bash script
F=''
for i in "$@"; do
F="$F \"${i//\"/\\\"}\""
done
/usr/local/bin/rar a ~/archive.rar $F
so it just takes the file paths, puts quotes around them, and then runs the RAR command with all the files as arguments. When I run this, automator gives me the error
Cannot open "/Users/user/test.txt" No such file or directory
Cannot create ~/archive.rar No such file or directory
No clue why it's getting those errors. When I add an echo to the last command
echo /usr/local/bin/rar a ~/archive.rar $F
The results are the exactly the command I need. I can copy and paste it in terminal and it works.
Does automator run bash scripts differently then they would run in terminal?
~
doesn't get expanded inside quotes, so you need at least~/"archive.rar"
there. And I would suspect some issues with handling spaces and quoting also for$F
. Does it work if you run it directly in Terminal?"$@"
to rar directly?