Alfred Workflows の Post Notification output : hkob の雑記録 (121)

はじめに

hkob の雑記録の第121回目は、Alfred Workflow の Post Notification output を解説します。

Post Notification output

Post Notification output は outputs の最初にあります。いよいよ最後のセッションです。

outputs

このオブジェクトの解説として、英語のマニュアルが用意されています。

www.alfredapp.com

Post Notification output はこんな形のものです。私のワークフローでは、Autoraise の切り替えを行うワークフローの結果を表示するために利用しています。

Post Notification output

Post Notification output の設定画面は以下のようになります。Notion AI に解説してもらいます。

Post Notification output の設定画面

このPost Notification outputのダイアログでは、以下の設定が可能です:

  • Title(タイトル)とText(テキスト): 通知として表示したいタイトルとテキストを設定できます。{query}というプレースホルダーは入力内容に置き換えられ、{var:varname}を使用して上流の変数を出力に組み込むことができます。
  • Only show if the input has content(入力内容がある場合のみ表示): このオプションをオンにすると、{query}が空でない場合にのみ通知が表示されます。
  • Last path component(最後のパスコンポーネント): ファイルパスから最後の部分のみを抽出します。
  • Remove extension(拡張子を削除): ファイル名から拡張子を削除します。

これらの設定により、入力内容に基づいて柔軟な通知表示が可能になります。特にLast path componentとRemove extensionは、ファイル名に関する基本的な修正を行うのに役立ちます。

Autoraise ワークフローの解説

せっかくなので、上記のワークフローの解説をしておきます。最初は Keyword input です。

Keyword input の設定画面

この結果、au とタイプするくらいで、toggle autoraise が起動する形になります。

toggle autoraise の実行画面

Keyword が指定されると、次の Run Script が実行されます。ここには zsh のスクリプトが書かれています。

設定したスクリプト

スクリプトは以下のようになっています。brew でインストールされた autoraise のサービスの起動状況を調べて、stop または start するだけの簡単なものです。autoraise が設定されていると、不意なウインドウ切り替えが起こるために普段はオフにしています。ただ、moodle でブラウザと Finder の Quick look 画面を行ったり来たりする時は、autoraise がかなり有効です。この時だけ autoraise をオンにするためにこのワークフローを設定しています。当初は単に切り替えるだけでしたが、今どちらになったのかがわからないので、最後に Post notification を追加したことになります。

check_service() {
    local service_name=$1
    if brew services list | grep $service_name | grep "started" > /dev/null; then
        return 0  # サービスが実行中
    else
        return 1  # サービスが停止中
    fi
}

if check_service "autoraise"; then
    brew services stop autoraise
else
    brew services start autoraise
fi

実行すると、こんな形で brew services の結果が表示されます。

brew service start

再度実行するとサービスが終了したことが通知されます。

brew service stop

おわりに

Post Notification output は、作業の結果を簡単に表示することができて便利です。これを利用している toggle autoraise はかなり便利に使っているワークフローです。いちいちターミナルでコマンドを実行しなくていいのが非常に楽です。

hkob.notion.site