Created
January 20, 2026 01:49
-
-
Save naoh16/558a23f3d6b7aca344bbd7626dde66de to your computer and use it in GitHub Desktop.
MMDAgent-EX で,キーワードによるGoogle検索結果をブラウザで表示したいときのAnyScript作成例 (PowerShell版)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mmda_google_search.ps1 | |
| # MMDAgent用 Google検索スクリプト(PowerShell版) | |
| # 指定されたキーワードでGoogle検索を行い,既定のブラウザで結果を表示する | |
| # | |
| # 重要: | |
| # このスクリプトファイルは UTF-8 BOM 付きで保存してください。 | |
| # VSCodeの場合,右下のエンコーディング文字列をクリックして, | |
| # 「UTF-8 with BOM」で保存してください。 | |
| # | |
| # MMDAgent(xxxx.mdf)での設定例: | |
| # Plugin_AnyScript_Command=powershell.exe -ExecutionPolicy Bypass -File "path\to\mmda_google_search.ps1" | |
| # | |
| # メッセージの仕様: | |
| # [入力/受信] | |
| # GOOGLE_SEARCH_START|検索キーワード | |
| # [出力/送信] | |
| # GOOGLE_SEARCH_EVENT_START | |
| # GOOGLE_SEARCH_EVENT_END | |
| # UTF-8 で入出力する設定(PowerShell 5.x / 7.x 両対応を意識) | |
| [Console]::InputEncoding = [System.Text.Encoding]::UTF8 | |
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 | |
| # Google検索を開く関数 | |
| function Open-GoogleSearch { | |
| param ( | |
| [string]$Query | |
| ) | |
| # URLエンコード(日本語対策) | |
| $encoded = [System.Uri]::EscapeDataString($Query) | |
| # Google検索URL | |
| $url = "https://www.google.com/search?q=$encoded" | |
| # 既定のブラウザで開く | |
| Start-Process $url | |
| } | |
| # メイン処理 | |
| while ($true) { | |
| # 標準入力から1行読む | |
| $instr = [Console]::ReadLine() | |
| # 入力が空、または EOF の場合は終了 | |
| if ([string]::IsNullOrWhiteSpace($instr)) { | |
| break | |
| } | |
| # GOOGLE_SEARCH_START|... にマッチするか確認 | |
| # 専用のイベントを設計し,適宜出力しておくと,ほかのモジュールで | |
| # そのイベントの有無を利用した動作設計が可能になる | |
| if ($instr -match '^GOOGLE_SEARCH_START\|(.*)$') { | |
| # 発話内容を抽出 | |
| $query = $Matches[1] | |
| # 例えば,以下のメッセージをFST側で受け取れたら | |
| # 「検索を開始します」と発言してみてもよい | |
| Write-Output "GOOGLE_SEARCH_EVENT_START" | |
| # Google検索を開く | |
| Open-GoogleSearch $query | |
| # 例えば,以下のメッセージをFST側で受け取れたら | |
| # 「検索を終了しました.ブラウザの画面を見てください.」と発言してみてもよい | |
| Write-Output "GOOGLE_SEARCH_EVENT_END" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment