9

シェル スクリプトを使用して、Bluetooth 経由で iPhone に接続する方法を見つけようとしています。私は現在、基本的にUIElementsを介してこれを行うapplescriptを使用していますが、これがコマンドラインユーティリティala blueutilで実行できるかどうか疑問に思っていますが、Bluetoothをオン/オフするだけでなく、デバイスに接続できますか? ご検討いただきありがとうございます。

-アフシン

4

8 に答える 8

10

この回答は、@Wolph の回答と非常によく似ています。しかし、他の問題と戦った後、これが私が思いついたものです。2 つの理由で気に入っています: # デバイスが既に接続されている場合、デバイスを切断しませんosascript

ファイルに保存して呼び出すだけですosascript path/to/file.applescript

これは 2014 年 4 月 11 日の時点で OSX Mavericks 10.9.2 で動作していましたが、セキュリティ設定パネルでこれを実行するために使用する方法へのアクセスを許可する必要がある場合があります。この Apple KB を参照してください: http://support.apple.com/kb/HT5914

"LG HBS730"デバイスの名前に一致するように文字列を変更するだけで、設定が完了します。リターンがあるので、 から素敵な出力が得られますosascript

activate application "SystemUIServer"
tell application "System Events"
  tell process "SystemUIServer"
    -- Working CONNECT Script.  Goes through the following:
    -- Clicks on Bluetooth Menu (OSX Top Menu Bar)
    --    => Clicks on LG HBS730 Item
    --      => Clicks on Connect Item
    set btMenu to (menu bar item 1 of menu bar 1 where description is "bluetooth")
    tell btMenu
      click
      tell (menu item "LG HBS730" of menu 1)
        click
        if exists menu item "Connect" of menu 1
          click menu item "Connect" of menu 1
          return "Connecting..."
        else
          click btMenu -- Close main BT drop down if Connect wasn't present
          return "Connect menu was not found, are you already connected?"
        end if
      end tell
    end tell
  end tell
end tell
于 2014-04-11T17:23:09.767 に答える
6

アンドリュー・バーンズの回答がヨセミテで機能するようにするには、少し変更する必要がありました。彼のコードは私に与え続けます

connect-mouse.scpt:509:514: 実行エラー: システム イベントでエラーが発生しました: アプリケーション プロセス "SystemUIServer" のメニュー バー 1 のメニュー バー項目 3 のメニュー 1 を取得できません。インデックスが無効です。(-1719)

そのようにメニューバーの項目を選択すると、それをクリックできるようになりますが、アップルスクリプトの不可解な理由により、メニューにはアクセスできません。この非常によく似たコードは私にとってはうまくいきます:

tell application "System Events" to tell process "SystemUIServer"
  set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
  click bt
  tell (first menu item whose title is "The Device Name") of menu of bt
    click
    tell menu 1
      if exists menu item "Connect"
        click menu item "Connect"
        return "Connecting..."
      else
        click bt  -- close main dropdown to clean up after ourselves
        return "No connect button; is it already connected?"
      end if
    end tell
  end tell
end tell

(first menu bar item whose description is "bluetooth") of menu bar 1との違いがわかりません(menu bar item 1 of menu bar 1 where description is "bluetooth")が…。

于 2015-04-28T21:23:33.043 に答える
5
于 2018-01-01T02:29:14.207 に答える
0

私が知る限り、Bluetooth のオン/オフを切り替えて、コマンド ラインでステータスを確認することしかできません ( blueutilを使用するか、で操作しlaunchctlます)。ただし、シェル経由でapplescriptルーチンを使用できますosascript

于 2013-07-08T06:17:28.617 に答える
0

複数の Bluetooth オーディオ デバイスがあります。したがって、Andrew のスクリプトは非常に役立ちます。これが彼のスクリプトへの私の修正です。私はプログラマー/IT 担当者ではありません。インターネットから少し学んだだけです。

set btchoice to BT_Choice()

on BT_Choice()

display dialog "Choose the device of your choice" with title "Selecting Device" buttons {"Bluedio", "Reconnect S-TS", "Anker A7721"} default button "Reconnect S-TS"

set Ndialogresult to the result
set DNameSel to button returned of Ndialogresult

display dialog "Whether to Connect or Disconnect the Device" with title "Handling Bluetooth" buttons {"Connect", "Disconnect", "Cancel"} default button "Connect"

set Bdialogresult to the result
set Bbuttonsel to button returned of Bdialogresult

activate application "SystemUIServer"
tell application "System Events"
    tell process "SystemUIServer"

        set btMenu to (menu bar item 1 of menu bar 1 where description is "bluetooth")
        tell btMenu
            click
            tell (menu item DNameSel of menu 1)
                click
                if exists menu item Bbuttonsel of menu 1 then
                    click menu item Bbuttonsel of menu 1
                    return "Connecting..."
                else
                    click btMenu -- Close main BT drop down if Connect wasn't present
                    return "Connect menu was not found, are you already connected?"
                end if
            end tell
        end tell
    end tell
end tell
end BT_Choice
于 2017-01-08T13:41:54.560 に答える