LoginSignup
2
1

More than 5 years have passed since last update.

el capitanでmenu extraをクリックするAppleScriptが動かなくなった

Last updated at Posted at 2015-10-03

悪魔

  • el capitanにアップデートしたら、Bluetoothまではクリックできるけどそこから先が進まない

検証

元のコード

click_menu_extra("bluetooth/myiPhone/ネットワークへ接続")

on split(sourceText, separator)
    if sourceText = "" then return {}
    set oldDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {separator}
    set theList to text items of sourceText
    set AppleScript's text item delimiters to oldDelimiters
    return theList
end split
on number_from(str)
    try
        str as number
    on error
        str
    end try
end number_from
on click_menu_extra(menu_path)
    if menu_path is "" then
        error "menu_path が入力されていません。"
    end if
    set mp to split(menu_path, "/")
    tell application "System Events"
        tell process "SystemUIServer"
            set frontmost to true
            click (menu bar 1's first menu bar item whose attribute "AXDescription"'s value is (mp's item 1))
            repeat with i from 2 to mp's length
                click (result's menu 1's menu item (my number_from(mp's item i)))
            end repeat
            delay 0.1 --連続してメニューを操作する時、ひと呼吸必要
        end tell
    end tell
end click_menu_extra

-> 「error "menu 1 of missing value を取り出すことはできません。" number -1728 from «class menE» 1 of missing value」のエラー。

該当箇所はclick (result's menu 1's menu item (my number_from(mp's item i)))

原因

メニューエクストラの一覧は取得できる。

tell application "System Events"
    tell process "SystemUIServer"
        get value of attribute "AXDescription" of every UI element of menu bar 1 --'s menu bar item 2
    end tell
end tell

->{"AppleScript", "bluetooth", "Wi-Fi、信号なし。", "text input", "バッテリー: 残り:62% ", "時計"}

Bluetoothの中身が取得できない。

tell application "System Events"
    tell process "SystemUIServer"
        get value of attribute "AXDescription" of every UI element of menu bar 1's menu bar item 2
    end tell
end tell

->{}

tell application "System Events"
    tell process "SystemUIServer"
        get every UI element of menu bar 1's menu bar item 2
    end tell
end tell

->{}

関係ある?

How can I reposition Fantastical's menu icon in my menu bar?
OS X El Capitan blocks menu extras so we are unable to offer a solution for this.

Flexibits | Fantastical 2 for Mac | FAQ

代替案

Wi-Fiテザリング?

親機(iPhone)のWi-Fiを常時オンにしたくないので。

コマンドラインでBluetoothテザリング有効化?

できないっぽい。以前にも必死に探したが見つからなかった。

ショートカットキーを送る?

ショートカットの「ステータスメニューを操作対象にする」から操作できるので、keystroke/key codeコマンドでやってやれなくはない。
というか、Bluetoothメニューをクリックして以降をkeystroke/key codeでやればいいっちゃいい。

tell application "System Events"
    click menu bar item 2 of menu bar 1 of application process "SystemUIServer"
    keystroke "m"
    delay 0.1
    key code 124
    delay 0.1
    key code 36
end tell

いちおう動いたが、keystrokeが始まるまでがえらく遅い。もう手で打ったほうがええわいってくらい。
なお、「ステータスメニューを操作対象にする」のショートカット(デフォルトでは^F8)を送るところから始めると、アクティブなアプリにむなしくkeystrokeが送られる事態が多発。

誰かいい知恵あったら教えてください

たのむ

2
1
2

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
2
1