Duck
Duck

Reputation: 35933

This script runs from Bash but not from Automator

I am creating a service for finder, using automator. The service has only one item: "run shell script" and the script is this:

currentDirectory=$(pwd)


for f in "$@"; do

  DIRNAME="$(dirname "$f")"

  export width=$( mdls "$f"  | grep kMDItemPixelWidth | tail -n1 | cut -d= -f2 )
  export height=$( mdls "$f" | grep kMDItemPixelHeight | tail -n1 | cut -d= -f2 )

  oneWidth=$((width / 3)) 
  oneHeight=$((height / 3))

  twoWidth=$((umWidth * 2 ))
  twoHeight=$((umHeight * 2 ))

  IFS='@3x' read -ra NAMES <<< "$f"    #Convert string to array

  basename=${NAMES[0]}
  extension="${f##*.}"

  fullnameOne=${NAMES[0]}.$extension
  fullnameTwo=${NAMES[0]}@2x.$extension

  sips -z "$oneWidth" "$oneHeight" "$f" --out "$DIRNAME"/"$fullnameOne"
  sips -z "$twoWidth" "$twoHeight" "$f" --out "$DIRNAME"/"$fullnameTwo"

done

The idea is this:

  1. I right click on a bunch of images which names contain @3x, like [email protected], [email protected], etc.
  2. I want the script to generate @2x and @1x versions of the files, renaming them [email protected], [email protected], file.png and ball.jpg respectively.
  3. The script has to respect the format. If the file is PNG, the output should be PNG and the same for JPG.

This script you see above runs from terminal, but not from automator. On automator the script generates just one file called Users.

What is wrong?

Upvotes: 0

Views: 146

Answers (1)

Jens
Jens

Reputation: 72619

What is wrong?

Likely the arguments to the script. To test this hypothesis, add

 printf '<%s>\n' "$@" >$HOME/debug.out

after currentDirectory=$(pwd).

If that doesn't help, also add set -x and redirect stderr to someplace you can find it.

Upvotes: 1

Related Questions