# Alfredで現在開いているフォルダ内の画像をImageOptimで圧縮するWorkflowの作り方 URL: https://webrandum.net/alfred-execute-imageoptim/ 公開日: 2019-08-22 更新日: 2019-08-21 カテゴリー: 作業効率化 タグ: Alfred, ImageOptim, Workflow 出典: Webrandum(著者: サイトウ マサカズ) 下記2つの記事を書いて思いついた合わせ技になります。 [![](https://www.google.com/s2/favicons?domain=webrandum.net)Webrandum![](//webrandum.net/mskz/wp-content/uploads/2019/08/eyecatch-18.jpg)ImageOptimをターミナルから起動する方法https://webrandum.net/imageoptim-run-from-terminal画像を圧縮するときは、ImageOptimを使うのをオススメしています。デフォルトの設定だと可逆圧縮(あとから元に戻せるような圧縮方法)になっているため、圧縮率は低いのですが、ちゃんと設定してあげればちゃんと圧縮してくれますし、1度設定してしまえばとりあえず画像をドラッグすればいいのでラクです。また、PNG・JPEG・SVG・GIFなどのWebで使う画像形式ほとんどに対応しているので、とりあえずImageOptimを通しておけばよくなるので便利です。ターミナルからImageOptimを起動したいそんな便利なImageOptimですが、わざわざImageO...](https://webrandum.net/imageoptim-run-from-terminal) [![](https://www.google.com/s2/favicons?domain=webrandum.net)Webrandum![](//webrandum.net/mskz/wp-content/uploads/2019/08/eyecatch-19.jpg)Alfred Workflowで、AppleScriptを使ってFinderとPath Finderの現在開いているパス...https://webrandum.net/alfred-workflow-get-pathAlfredのWorkflowを使っていると、FinderやPath Finderで開いているパスを取得して、そのパスに対してなにか操作したいときがあります。今回はFinderとPath Finderそれぞれのパスの取得方法と、どちらかアクティブになっている方を取得する方法をまとめておきます。AlfredのWorkflowでAppleScriptを使う方法AlfredのWorkflowでAppleScriptを使いたいときは、Workflowの編集画面で右クリックして[Actions]→[Run NSAppleScript]を選択します。下の画像のようなパネルが表示されます。この中にAppleScriptを書いていくのですが、最初...](https://webrandum.net/alfred-workflow-get-path) ## 作りたいWorkflow 現在ImageOptimで画像の圧縮をしたいときの自分のフローは下記の通りです。 1. 画像フォルダを開いて、画像を選択 2. AlfredでImageOptimを起動 3. ImageOptimに画像をドラッグして圧縮 もし、Workflowができると下記のようになります。 1. 画像フォルダを開く 2. AlfredからWorkflowを実行して圧縮 Finderで開いているフォルダ内の画像を圧縮するようにすれば、画像を選択する必要もないですし、Alfredからの実行後、すぐ圧縮されるのはストレスフリーですよね。 ## Workflowの作成 まずはAlfredの環境設定の[Workflows]のサイドバー下の「+」ボタンを押し、「Blank Workflow」をクリックして必要情報を入力します。 今回の場合はImageOptimを実行するWorkflowなので、名前は「Execute ImageOptim」としておきます。 ![Workflowの作成](https://webrandum.net/mskz/wp-content/uploads/2019/08/image_1-19-1024x571.png) ### キーワード部分の設定 黒い背景部分を右クリックして、[Inputs]→[Keyword]を選択します。 キーワードに関してはImageOptimの略で「io」にして、引数はなしにしたいので「No Argument」を選択します。 ![入力キーワードの設定](https://webrandum.net/mskz/wp-content/uploads/2019/08/image_2-16-1024x571.png) あとはタイトルやサブタイトルなどの情報を入力して「Save」をクリックします。 ### Finderからのパス取得部分の設定 Keywordの右横にあるポッチをクリックして、[Actions]→[Run NSAppleScript]を選択します。 自分はPath FinderとFinderを併用しているので、下記のコードをコピペします。 ``` on alfred_script(q) tell application "System Events" set appName to name of the first process whose frontmost is true end tell if appName is "Finder" then tell application "Finder" set pathList to POSIX path of (folder of the front window as alias) return pathList end tell else tell application "Path Finder" set pathList to POSIX path of the target of the front finder window return pathList end tell end if end alfred_script ``` ![Finderのパスを取得](https://webrandum.net/mskz/wp-content/uploads/2019/08/image_3-14-1024x571.png) 詳細な内容は[過去に記事](https://webrandum.net/alfred-workflow-get-path/)にしているので、Finderのみでいい方などはこちらを参考にしてください。 [![](https://www.google.com/s2/favicons?domain=webrandum.net)Webrandum![](//webrandum.net/mskz/wp-content/uploads/2019/08/eyecatch-19.jpg)Alfred Workflowで、AppleScriptを使ってFinderとPath Finderの現在開いているパス...https://webrandum.net/alfred-workflow-get-pathAlfredのWorkflowを使っていると、FinderやPath Finderで開いているパスを取得して、そのパスに対してなにか操作したいときがあります。今回はFinderとPath Finderそれぞれのパスの取得方法と、どちらかアクティブになっている方を取得する方法をまとめておきます。AlfredのWorkflowでAppleScriptを使う方法AlfredのWorkflowでAppleScriptを使いたいときは、Workflowの編集画面で右クリックして[Actions]→[Run NSAppleScript]を選択します。下の画像のようなパネルが表示されます。この中にAppleScriptを書いていくのですが、最初...](https://webrandum.net/alfred-workflow-get-path) ### ImageOptim起動部分の設定 Run NSAppleScriptの右横にあるポッチをクリックして、[Actions]→[Terminal Command]を選択して下記コマンドを設定します。 ``` open -a ImageOptim.app {query}/* ``` もしPNG画像に限定したい場合は、最後を`*.png`にすればOKです。 ![ImageOptimを実行するコマンドの設定](https://webrandum.net/mskz/wp-content/uploads/2019/08/image_4-6-1024x571.png) ちなみに、フォルダ名にスペースが入っている場合はうまく動作してくれないので、下の「Escaping:」にある「Spaces」をチェックしてエスケープしておくとより安全だと思います。 これで完成なので、ちゃんと動作するか試してみましょう。 ## まとめ ImageOptim以外にも、いまFinderで選択しているファイルを特定アプリで開くというのは色々できそうですね。 ものによっては少し工夫が必要かもしれませんが、基本的には似たようなWorkflowで作れそうです。