自动压缩截图

2020年04月15日 23:33
Ref: Gitlab, Blog
Keywords:

先装压缩库

brew install pngquant zopfli

用 Automator 创建一个名为 CompressScreenshotFolder Action,选择监听 Desktop,然后创建一个 Run Shell Script,注意 Pass Input as argument

for f in "$@"
do
  if [[ $(file --mime-type -b "$f") == image/*g ]]; then
    /usr/local/bin/pngquant 64 --skip-if-larger --ext=.png --force "$f"
    /usr/local/bin/zopflipng -y "$f" "$f"
  fi
done
Code
先装[[压缩库|https://github.com/google/zopfli]]。

```shell
brew install pngquant zopfli
```

用 Automator 创建一个名为 `CompressScreenshot` 的 [[Folder Action|MacAutomataFolderAction]],选择监听 Desktop,然后创建一个 `Run Shell Script`,注意 Pass Input `as argument`。

```shell
for f in "$@"
do
  if [[ $(file --mime-type -b "$f") == image/*g ]]; then
    /usr/local/bin/pngquant 64 --skip-if-larger --ext=.png --force "$f"
    /usr/local/bin/zopflipng -y "$f" "$f"
  fi
done
```