Skip to content

Instantly share code, notes, and snippets.

@Hodglim
Created July 17, 2018 11:36
Show Gist options
  • Save Hodglim/6b860d0e0188dac5df541b9be9245a5f to your computer and use it in GitHub Desktop.
Save Hodglim/6b860d0e0188dac5df541b9be9245a5f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# <bitbar.title>Battery Apple Bluetooth keyboard</bitbar.title>
# <bitbar.version>1.0</bitbar.version>
# <bitbar.author>Alexandre Espinosa Menor</bitbar.author>
# <bitbar.author.github>alexandregz</bitbar.author.github>
# <bitbar.desc>Show battery percentage for Bluetooth Keyboard</bitbar.desc>
# <bitbar.image>http://i.imgur.com/1FlcPYx.png</bitbar.image>
#
# command from https://github.com/matryer/bitbar-plugins/issues/84 by @keithamus
# works fine with Apple Keyboard
#
require 'yaml'
output = YAML.load(`system_profiler SPBluetoothDataType`);
output['Bluetooth']['Devices (Paired, Configured, etc.)'].each do |device|
puts "🖱 "+device[1]['Battery Level'].to_s if device[1]['Minor Type'].eql?('Mouse') && device[1].has_key?('Battery Level')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment