This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- user input (name of magic keybord and magic mouse: system preferences > bluetooth) | |
set keyboard to "Magic Keyboard" | |
set mouse to "Magic Mouse 2" | |
-- end of user input | |
set aa to do shell script "system_profiler SPBluetoothDataType | grep '" & keyboard & "\\|Connected'" | |
set apple_std to text item delimiters | |
set text item delimiters to ":" | |
set aa_list to aa's text items | |
if (item 4 of aa_list) contains "Yes" then | |
set s_key to 1 | |
else | |
set s_key to 0 | |
set kbat to keyboard & " is Not Connected!" | |
end if | |
set text item delimiters to apple_std | |
set aa to do shell script "system_profiler SPBluetoothDataType | grep '" & mouse & "\\|Connected'" | |
set apple_std to text item delimiters | |
set text item delimiters to ":" | |
set aa_list to aa's text items | |
if (item 4 of aa_list) contains mouse and (item 4 of aa_list) contains "connected" then | |
if (item 5 of aa_list) contains "yes" then | |
set s_mouse to 1 | |
else | |
set s_mouse to 0 | |
set mbat to mouse & " is Not Connected!" | |
end if | |
else | |
if (item 4 of aa_list) contains "yes" then | |
set s_mouse to 1 | |
else | |
set s_mouse to 0 | |
set mbat to mouse & " is Not Connected!" | |
end if | |
end if | |
set text item delimiters to apple_std | |
if s_mouse is 1 then | |
set bb to do shell script "system_profiler SPBluetoothDataType | grep '" & mouse & "\\|Battery'" | |
set apple_std to text item delimiters | |
set text item delimiters to ":" | |
set bb_list to bb's text items | |
set bb_list_count to count bb_list | |
if bb_list_count > 4 then | |
if (item 5 of bb_list) contains "%" then | |
set mbat to mouse & ": " & (item 5 of bb_list) | |
end if | |
else | |
set mbat to mouse & ": " & (item 4 of bb_list) | |
end if | |
set apple_std to text item delimiters | |
end if --s_mouse is 1 | |
if s_key is 1 then | |
set bb to do shell script "system_profiler SPBluetoothDataType | grep '" & keyboard & "\\|Battery'" | |
set apple_std to text item delimiters | |
set text item delimiters to ":" | |
set bb_list to bb's text items | |
if (item 3 of bb_list) contains "Battery Level" and (item 3 of bb_list) contains keyboard and (item 4 of bb_list) contains "%" and (item 4 of bb_list) contains "Battery Level" then | |
set tar to (item 4 of bb_list) | |
set text item delimiters to "%" | |
set bb2_list to tar's text items | |
set kbat to keyboard & ": " & (item 1 of bb2_list) & "%" | |
else | |
if (item 3 of bb_list) contains "Battery Level" and (item 3 of bb_list) contains keyboard then | |
set kbat to keyboard & ": " & (item 4 of bb_list) | |
end if | |
end if | |
set apple_std to text item delimiters | |
end if -- if s_key is 1 then | |
tell application "System Events" | |
display dialog kbat & " | |
" & mbat with title "Bettery Level" | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment