Frage

I have a nice working Folder Action, which watermarks every picture in a folder and put them in a folder.

watermark=~/Dropbox/Business/mihalko_logo_bw.png
shopt -s nocasematch
for f; do
  [[ $f =~ .*\.(jpe?g|png)$ ]] || continue
  d="${f%/*}/wm_$(date +%Y_%m_%d)"
  mkdir -p "$d"
  target="$d/${f##*/}"
  size=$(/usr/local/bin/identify -format '%[fx:w/4,279]' "$f")
  /usr/local/bin/composite -dissolve 10% -gravity SouthEast\
  \( $watermark -geometry $size \) "$f" -quality 100 "$target"
  rm $f
done
~/imageoptim-cli/bin/imageOptim --jpeg-mini --image-alpha --quit --directory "$d"

Unfortunatelly, FA is working only in one directory. I tried to create a Service from this code, without success. Does anybody knows what modifications/automator action are needed in this case?

War es hilfreich?

Lösung

Using an associative array:

watermark=~/Dropbox/Business/mihalko_logo_bw.png
shopt -s nocasematch

declare -A dirs

for f; do
  [[ $f =~ .*\.(jpe?g|png)$ ]] || continue
  d="${f%/*}/wm_$(date +%Y_%m_%d)"
  mkdir -p "$d"
  dirs["$d"]="$d"
  target="$d/${f##*/}"
  size=$(/usr/local/bin/identify -format '%[fx:w/4,279]' "$f")
  /usr/local/bin/composite -dissolve 10% -gravity SouthEast\
  \( "$watermark" -geometry $size \) "$f" -quality 100 "$target"
  rm "$f"
done

for d in "${dirs[@]}"; do
  ~/imageoptim-cli/bin/imageOptim --jpeg-mini --image-alpha --quit --directory "$d"
done

Andere Tipps

Unfortunatelly, FA is working only in one directory. I tried to create a Service from this code, without success. Does anybody knows what modifications/automator action are needed in this case?

If you have a Folder Action set up, you should be able to attach the Folder Action to other folders by

  1. Go into the Finder
  2. Right-click on the folder that you want to attach the Folder Action to.
  3. Choose the first item from the contextual menu, "Folder Action Setup":

Folder Action Setup

  1. Choosing this menu item will bring up a window in which you can attach your Folder Action to other folders.

If you need to create a Service using Automator, you can do the following:

  1. Run the Automator app
  2. Create a new Service
  3. Add an action called: "Run Shell Script" to your wokflow.
  4. Copy and paste your code into the shell script action.
  5. Choose the input type and applications that the Service can work with.

I hope that this helps you.

You can send me an email at: kaydell@yahoo.com if I can be of further assistance.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top