Applescript для подключения к устройству bluetooth

Я пытаюсь создать applescript, позволяющий мне подключаться к устройству bluetooth по его идентификатору Bluetooth.

до сих пор мне удалось получить applescript для включения bluetooth, если он выключен. Вот такой код:

# This is only necessary, if AppleScripts are not yet allowed to change checkboxes
tell application "System Events" to set UI elements enabled to true
# Now change the bluetooth status
  tell application "System Preferences"
    set current pane to pane id "com.apple.preferences.bluetooth"
      tell application "System Events"
        tell process "System Preferences"
        # Enabled is checkbox number 2
        if value of checkbox 2 of window "Bluetooth" is 0 then
            click checkbox 2 of window "Bluetooth"
        end if
    end tell
end tell
quit
end tell

будет ли кто-то знать, если и как можно настроить новое устройство bluetooth, и если было бы возможно подключиться к устройству на основе его имени устройства/ это устройство bluetooth ID?

Я также попытался записать действие в Automator но для опции " настроить новое устройство "Automator просто говорит мне: "нажмите" кнопку".
Спасибо

1
задан mhorgan
22.05.2023 4:41 Количество просмотров материала 2498
Распечатать страницу

1 ответ

мне удалось это сделать благодаря этой ссылке предоставлено @mu3 в комментариях. Вот сценарий Apple:

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 device Item
        --      => Clicks on Connect Item
        set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
        tell btMenu
            click
            tell (menu item "Beats Solo³ de Anthonin" of menu 1)
                click
                if exists menu item "Connect" of menu 1 then
                    click menu item "Connect" of menu 1
                    return "Connecting..."
                else
                    key code 53 -- 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

все, что вам нужно сделать, это заменить "Beats Solo3 de Anthonin" именем вашего устройства, и если ваш компьютер не на английском языке, замените "Connect" его переводом на ваш язык.

надеюсь, что это помогает :)

0
отвечен AnthoPak 2023-05-23 12:29

Постоянная ссылка на данную страницу: [ Скопировать ссылку | Сгенерировать QR-код ]

Ваш ответ

Опубликуйте как Гость или авторизуйтесь

Имя
Вверх