RaycastでPLaMo翻訳を使う

2025-06-21
#raycast
  1. tl;dr
  2. 経緯
  3. Raycast Script Commandとは
  4. 実装
    1. スクリプト全体
    2. ポイント
  5. セットアップ
  6. おわり

tl;dr

Raycast Script Command機能を使って、日本語/英語の翻訳を即時実行できるようにした。 PLaMo翻訳モデルをローカルで動かすことで、ネットワーク接続不要で比較的高速な翻訳が可能。

経緯

これまでRaycastAI機能を使い、Ollamaをバックエンドにしてqwen3:4bで日英翻訳していた。

へいほぅ on mixi2

qwen:4bでも用途を短めの日英翻訳に限定すれば充分すぎる性能だということが分かった

mixi.social

ローカルでこの精度の翻訳ができることには感動ものなのだが、やはりプロプライエタリLLMと比較すると遅いし長文になると精度に難があるので少し不満があった。

そこで、Preferred Networksが公開しているplamo-translate-cliをRaycastのScript Commandから呼び出せるようにしようと考えた。

Raycast Script Commandとは

RaycastのScript Command機能は、任意のスクリプトをRaycastから実行できる機能である。shell script以外にも対応している。 メタデータをスクリプトのコメントとして埋め込み、フォルダを登録しておくことでRaycastが認識してくれる。

GitHub - raycast/script-commands: Script Commands let you tailor Raycast to your needs. Think of them as little productivity boosts throughout your day.

Script Commands let you tailor Raycast to your needs. Think of them as little productivity boosts throughout your day. - raycast/script-commands

github.com

主要なパラメータ:

実装

スクリプト全体

やっていることは単純で、引数として渡されたテキストを入力として plamo-translate コマンドを実行するだけ。

#!/usr/bin/env bash

set -Eeufo pipefail

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Translate ja <-> en with PLaMo
# @raycast.mode fullOutput

# Optional parameters:
# @raycast.icon 🌐
# @raycast.argument1 { "type": "text", "placeholder": "text (ja/en)" }

# Documentation:
# @raycast.author h3y6e
# @raycast.authorURL https://raycast.com/h3y6e

export PATH="$HOME/.local/share/mise/shims:$PATH"

if ! command -v plamo-translate >/dev/null 2>&1; then
  echo >&2 "Error: plamo-translate not found"
  exit 1
fi

plamo-translate --input "$1"

dotfilesで公開している

dotfiles/dot_config/raycast-script/executable_plamo-translate.sh at main · h3y6e/dotfiles · GitHub

my dotfiles. Contribute to h3y6e/dotfiles development by creating an account on GitHub.

github.com

ポイント

fullOutputモード

# @raycast.mode fullOutput

翻訳結果は複数行になることがあるため、fullOutput モードを使用している。これにより、翻訳結果全体が表示される。

mise経由でのコマンド実行

export PATH="$HOME/.local/share/mise/shims:$PATH"

自分はmiseを使って各種runtimeを管理している。 Raycastから実行される際はPATHが通っていないため、明示的にmiseのshimsディレクトリをPATHに追加している。

セットアップ

Raycast Script Commandの設定

  1. スクリプトを ~/.config/raycast-script/ ディレクトリ(任意)に配置

  2. 実行権限を付与: chmod +x plamo-translate.sh

  3. Raycastで Extensions → Script Commands → Add Directories を選択し、上記ディレクトリを追加

plamo-translate-cliのインストール

mise設定ファイル(~/.config/mise/config.toml)に以下を追加:

"pipx:pfnet/plamo-translate-cli" = { version = "latest", uvx_args = "-p 3.12" }

そして mise install を実行

おわり

Raycast Script CommandとPLaMo翻訳CLIの組み合わせで、開発中の翻訳作業が格段に楽になった。 同様の仕組みで他のCLIツールもRaycastから呼び出せるようにできるので、色々試してみたい。