6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

任意のメニューを選択状態にするスクリプト

Last updated at Posted at 2016-12-16

AppleScriptでメニューを選択状態にする

概要

メニューをクリックされたのを検知することはよくあるが,こちらで選択状態に制御できるようにする.
つまり,クリックはされていないが,メニュー項目が青でハイライトされている状態.

環境

Mac OS Sierra
AppleScript

雛形

tell application "System Events"
    tell process "Script Editor"

    end tell
end tell

説明するコードは雛形の3行目に書くものとします.
アプリケーションはScript Editorを使います(他のアプリケーションでも可).

メニュー項目を選択状態にする

(1)
メニューバーの中のメニューを開くには
click menu bar 1's menu bar item "ファイル"
もしくは,インデックスを使い,
click menu bar 1's menu bar item 3
のようにしてできます.

(2)
click menu bar 1's menu bar item "ファイル"
上記でメニューを開いた状態で
select menu bar 1's menu bar item "ファイル"'s menu 1's menu item 1
のようにselect命令をすると選択状態(青でハイライトされた状態)となります.
簡単ですね.

(3)
さらにその中の項目を決定させるには
click menu bar 1's menu bar item "ファイル"'s menu 1's menu item "新規"
または
click menu bar 1's menu bar item "ファイル"'s menu 1's menu item 1
のようにします.

これでボタンが押されるとメニューを移動し,自由にメニュー項目を動き回るアプリケーションを作ったりできます.

コード全体

選択状態にするまでのコードです.

tell application "System Events"
    tell process "Script Editor"
            click menu bar 1's menu bar item "ファイル"
            select menu bar 1's menu bar item "ファイル"'s menu 1's menu item 1
    end tell
end tell

イメージ

スクリーンショット 2016-12-16 14.58.38.png

感想

簡単だが,柔軟なメニュー選択ができそうな気がした.

6
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?