AutomatorでGoogle Chromeのタブのテキストをクリップボードにコピーしたい

Automatorにおいて下記の動作をするシェルスクリプトの記述をお教え願えないでしょうか?


  1. (Google Chromeブラウザがアクティブな状態で)Chromeのアクティブなタブのタイトルを変数theTitleに取得する
  2. そのタイトルをクリップボードにコピーする
  3. クリップボードの中身をダイアログに表示する


環境

  • MacBook Pro 13-inch 2020 / OS v. 12.1 (Monterey)
  • Automator v. 2.10 (512)


ネットの様々な記述を参考に試みたのですがうまくいきませんでした。どうかよろしくお願い申し上げます。

MacBook Pro (2020 and later)

投稿日 2022/01/31 08:24

返信
スレッドに付いたマーク ランキングトップの返信

投稿日 2022/01/31 17:40

とりあえず3案考えてみました。シェルスクリプトではなく AppleScript で良ければA案がシンプルで良いと思います。動作確認は Mojave 10.14.6 ですが、Monterey でも大丈夫だと思います。多分...。


当方の環境

  • Mojave 10.14.6 (Parallels Desktop 15)
  • Google Chrome 97.0.4692.99
  • Automator 2.9


ーーーーー


A案

  • 「シェルスクリプトを実行」アクションではなく「AppleScriptを実行」アクションを使用


on run
    tell application "Google Chrome"
        activate
        # 1. Google Chrome のアクティブなタブのタイトルを変数 theTitle に格納
        set theTitle to window 1's active tab's title

        # 2. タイトルをクリップボードにコピー
        set the clipboard to theTitle

        # 3. クリップボードの中身をダイアログに表示
        display dialog theTitle
    end tell
    return theTitle
end run


ーーーーー


B案

  • シェルスクリプトを実行アクションを使用 (bash か zsh)
  • A案をそのままラッピング


theTitle=$(osascript <<'EOF'
on run
    tell application "Google Chrome"
        activate
        set theTitle to window 1's active tab's title
        set the clipboard to theTitle
        display dialog theTitle
    end tell
    return theTitle
end run
EOF
)

echo "${theTitle}"


ーーーーー


C案

  • シェルスクリプトを実行アクションを使用 (bash か zsh)


theTitle=$(osascript <<'EOF'
on run
    tell application "Google Chrome"
        return window 1's active tab's name
    end tell
end run
EOF
)

LANG=en_US.UTF-8 pbcopy <<< "${theTitle}"

osascript <<'EOF' - "${theTitle}"
on run (argv)
    tell application "Google Chrome"
        activate
        display dialog (argv's item 1 as text)
    end tell
    return
end run
EOF

echo "${theTitle}"


返信: 4

返信はありません。

このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

AutomatorでGoogle Chromeのタブのテキストをクリップボードにコピーしたい

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。