0

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?

2
  • I miss the shebang. Commented Aug 26, 2015 at 16:23
  • IFS doesn't work the way you think it does. Check the value of $f compared to the resulting value of $basename. Commented Aug 26, 2015 at 16:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Each argument is likely to be a full path, /Users/someone/path/to/[email protected].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.