Показывать Bluetooth / громкость в строке меню Apple Script - PullRequest
0 голосов
/ 04 мая 2020

У меня есть рабочий скрипт, который я хотел бы посмотреть, есть ли способ скрыть или просто запустить скрипт в фоновом режиме. Текущий рабочий скрипт физически активирует панель, поэтому пользователь видит, что это происходит перед ними.

tell application "System Preferences"
    activate
    set the current pane to pane "Bluetooth"
    delay 1
end tell

tell application "System Events"
    tell process "System Preferences"
        set toggleBluetooth to the checkbox "Show Bluetooth in menu bar" of the window "Bluetooth"
        click toggleBluetooth
    end tell
end tell

Я также нашел способ мгновенно включить некоторые вещи и задавался вопросом, есть ли способ взять это и заставить его работать с блютузом и громкостью.

tell application "Finder"
    tell Finder preferences
        set desktop shows hard disks to true
    end tell
end tell

1 Ответ

0 голосов
/ 06 мая 2020

Этот следующий код AppleScript можно использовать для включения и выключения элемента строки меню Bluetooth без переноса Системных настроек на передний план.

if application "System Preferences" is running then
    do shell script "killall 'System Preferences'"
    repeat until application "System Preferences" is not running
        delay 0.1
    end repeat
end if

tell application "System Preferences"
    reveal anchor "Main" of pane id "com.apple.preferences.Bluetooth"
end tell

tell application "System Events"
    repeat until checkbox "Show Bluetooth in menu bar" of window "Bluetooth" of application process "System Preferences" exists
        delay 0.1
    end repeat
    click checkbox "Show Bluetooth in menu bar" of window "Bluetooth" of application process "System Preferences"
end tell

tell application "System Preferences" to quit

И это будет делать то же самое для значка громкости в строке меню

if application "System Preferences" is running then
    do shell script "killall 'System Preferences'"
    repeat until application "System Preferences" is not running
        delay 0.1
    end repeat
end if

tell application "System Preferences"
    reveal anchor "output" of pane id "com.apple.preference.sound"
end tell

tell application "System Events"
    repeat until checkbox "Show volume in menu bar" of window "Sound" of application process "System Preferences" exists
        delay 0.1
    end repeat
    click checkbox "Show volume in menu bar" of window "Sound" of application process "System Preferences"
end tell

tell application "System Preferences" to quit
...