{"id":19,"date":"2011-04-21T09:00:00","date_gmt":"2011-04-21T09:00:00","guid":{"rendered":"http:\/\/mattdturner.com\/wordpress\/?p=19"},"modified":"2013-11-04T10:56:54","modified_gmt":"2013-11-04T17:56:54","slug":"mac-bluetooth-keyboardmouse-battery-level-in-terminal","status":"publish","type":"post","link":"http:\/\/mattdturner.com\/wordpress\/2011\/04\/mac-bluetooth-keyboardmouse-battery-level-in-terminal\/","title":{"rendered":"Mac Bluetooth Keyboard\/Mouse Battery Level in Terminal"},"content":{"rendered":"<p>There are a few reasons why somebody might want to check the current battery percentage of a bluetooth mouse and\/or keyboard within Terminal on a mac. \u00a0Some that come to mind are for use in <a href=\"http:\/\/projects.tynsoe.org\/en\/geektool\/\">GeekTool<\/a>, if you are connected to the computer remotely through ssh, etc.<\/p>\n<p>Well as it turns out, its actually very easy to do. \u00a0The tool that we will use to check the battery percentage is called &#8220;ioreg&#8221;. \u00a0The Mac OS X manual describes ioreg as a tool that &#8220;displays the I\/O Kit registry. It shows the\u00a0hierarchical\u00a0registry structure as an inverted tree.&#8221;<\/p>\n<p>There are many options available with the ioreg tool, however this article will just be discussing how to check the battery percentage of different devices. \u00a0See the below text for the code to view the battery percentage:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">ioreg -n &quot;IOAppleBluetoothHIDDriver&quot; | grep -i &quot;batterypercent&quot; | sed 's\/[^[:digit:]]\/\/g'\r\n49\r\nioreg -n &quot;BNBMouseDevice&quot; | grep -i &quot;batterypercent&quot; | sed 's\/[^[:digit:]]\/\/g'\r\n45\r\nioreg -n &quot;BNBMouseDevice&quot; | grep -i &quot;batterypercent&quot;\r\n    | |   |     | | |   |   &quot;BatteryPercent&quot; = 45\r\n<\/pre>\n<p><!--more--><\/p>\n<p>There are a few things that should be noted about the above commands.<\/p>\n<ol>\n<li>The <code>-n<\/code> option is used to show the object properties ONLY for the corresponding object name.<\/li>\n<li>The <code>grep<\/code> command is used to only show lines that contains the term &#8220;batterypercent&#8221;.\n<ol>\n<li>The <code>-i<\/code> in the grep command is used to ignore case in &#8220;batterypercent&#8221;.<\/li>\n<\/ol>\n<\/li>\n<li>The <code>sed<\/code> command is used to parse the output text so that it only shows the actual number percentage.<\/li>\n<\/ol>\n<div>If, for some reason, your device names are different then you just need to type <code>ioreg -l<\/code> to get an output of all objects. \u00a0Now you can use the Find utility in terminal to search for &#8220;batterypercent&#8221;. \u00a0There should be very few instances of the string. \u00a0A few lines above the &#8220;batterypercent&#8221; property, you should see another property that is called &#8220;product&#8221;. \u00a0This property tells you which device you are looking at. \u00a0Once you know which device it is, you can continue to browse the lines above until you see a line that starts with\u00a0+-o. \u00a0This is the object name. \u00a0See the example below:<\/div>\n<div>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n    | |   |     | | | +-o BNBMouseDevice\r\n    | |   |     | | |   | {\r\n    | |   |     | | |   |   &quot;PrimaryUsagePage&quot; = 1\r\n    | |   |     | | |   |   &quot;MaxInputReportSize&quot; = 6\r\n    | |   |     | | |   |   &quot;IOUserClientClass&quot; = &quot;IOHIDLibUserClient&quot;\r\n    | |   |     | | |   |   &quot;BatteryPanic&quot; = No\r\n    | |   |     | | |   |   &quot;VendorID&quot; = 1452\r\n    | |   |     | | |   |   &quot;VersionNumber&quot; = 132\r\n    | |   |     | | |   |   &quot;DeviceAddress&quot; = &quot;34-15-9e-d0-27-aa&quot;\r\n    | |   |     | | |   |   &quot;HIDPointerResolution&quot; = 104595456\r\n    | |   |     | | |   |   &quot;HIDDescriptor&quot; = ((34,&lt;05010902a10185100509190129021500250195027501810$\r\n    | |   |     | | |   |   &quot;SuspendSupported&quot; = Yes\r\n    | |   |     | | |   |   &quot;ExtendedFeatures&quot; = {&quot;SuperMode&quot;={&quot;size&quot;=1,&quot;id&quot;=215,&quot;min&quot;=0,&quot;max&quot;=1,&quot;t$\r\n    | |   |     | | |   |   &quot;MaxFeatureReportSize&quot; = 65\r\n    | |   |     | | |   |   &quot;Product&quot; = &quot;Magic Mouse&quot;\r\n    | |   |     | | |   |   &quot;SerialNumber&quot; = &quot;34-15-9e-d0-27-aa&quot;\r\n    | |   |     | | |   |   &quot;PSM&quot; = 17\r\n    | |   |     | | |   |   &quot;BatteryLow&quot; = No\r\n    | |   |     | | |   |   &quot;Transport&quot; = &quot;Bluetooth&quot;\r\n    | |   |     | | |   |   &quot;Elements&quot; = ({&quot;ReportID&quot;=0,&quot;ElementCookie&quot;=1,&quot;CollectionType&quot;=1,&quot;Type&quot;$\r\n    | |   |     | | |   |   &quot;MouseButtonDivision&quot; = 55\r\n    | |   |     | | |   |   &quot;SetReportTimeoutMS&quot; = 3500\r\n    | |   |     | | |   |   &quot;BatteryLowNotificationType&quot; = 1835887727\r\n    | |   |     | | |   |   &quot;Manufacturer&quot; = &quot;Apple&quot;\r\n    | |   |     | | |   |   &quot;ConnectionNotificationType&quot; = 1835885427\r\n    | |   |     | | |   |   &quot;ProductID&quot; = 781\r\n    | |   |     | | |   |   &quot;IOPowerManagement&quot; = {&quot;CurrentPowerState&quot;=1}\r\n    | |   |     | | |   |   &quot;BatteryDangerouslyLowNotificationType&quot; = 1836082284\r\n    | |   |     | | |   |   &quot;DeviceUsagePairs&quot; = ({&quot;DeviceUsagePage&quot;=1,&quot;DeviceUsage&quot;=2},{&quot;DeviceUsa$\r\n    | |   |     | | |   |   &quot;BD_ADDR&quot; = &lt;34159ed027aa&gt;\r\n    | |   |     | | |   |   &quot;BatteryPercent&quot; = 45\r\n    | |   |     | | |   |   &quot;MouseButtonMode&quot; = &quot;TwoButton&quot;\r\n    | |   |     | | |   |   &quot;ClassOfDevice&quot; = 9600\r\n    | |   |     | | |   |   &quot;DefaultMultitouchProperties&quot; = {&quot;parser-type&quot;=2000,&quot;parser-options&quot;=4,$\r\n    | |   |     | | |   |   &quot;BTHIDObjectID&quot; = 148620288\r\n    | |   |     | | |   |   &quot;InputReportElements&quot; = ({&quot;ReportID&quot;=16,&quot;ElementCookie&quot;=73,&quot;Size&quot;=48,&quot;R$\r\n    | |   |     | | |   |   &quot;VendorIDSource&quot; = 2\r\n    | |   |     | | |   |   &quot;ReportInterval&quot; = 11250\r\n    | |   |     | | |   |   &quot;CFBundleIdentifier&quot; = &quot;com.apple.driver.AppleBluetoothMultitouch&quot;\r\n    | |   |     | | |   |   &quot;MaxOutputReportSize&quot; = 1\r\n    | |   |     | | |   |   &quot;IOCFPlugInTypes&quot; = {&quot;7DDEECA8-A7B4-11DA-8A0E-0014519758EF&quot;=&quot;IOHIDFamil$\r\n    | |   |     | | |   |   &quot;IOProviderClass&quot; = &quot;IOBluetoothL2CAPChannel&quot;\r\n    | |   |     | | |   |   &quot;LocationID&quot; = 516958122\r\n    | |   |     | | |   |   &quot;IOClass&quot; = &quot;BNBMouseDevice&quot;\r\n    | |   |     | | |   |   &quot;DisconnectionNotificationType&quot; = 1835885683\r\n    | |   |     | | |   |   &quot;DeviceName&quot; = &quot;Magic Mouse&quot;\r\n    | |   |     | | |   |   &quot;HIDDefaultBehavior&quot; = &quot;Mouse&quot;\r\n    | |   |     | | |   |   &quot;DefaultMultitouchPreferences&quot; = {&quot;MouseHorizontalSwipe&quot;=2,&quot;MouseMoment$\r\n    | |   |     | | |   |   &quot;CountryCode&quot; = 0\r\n    | |   |     | | |   |   &quot;IOMatchCategory&quot; = &quot;IODefaultMatchCategory&quot;\r\n    | |   |     | | |   |   &quot;PrimaryUsage&quot; = 2\r\n    | |   |     | | |   |   &quot;IOProbeScore&quot; = 1010\r\n    | |   |     | | |   |   &quot;GetReportTimeoutMS&quot; = 3500\r\n    | |   |     | | |   |   &quot;IOGeneralInterest&quot; = &quot;IOCommand is not serializable&quot;\r\n    | |   |     | | |   | }\r\n<\/pre>\n<\/div>\n<div>\n<p>Line 31 shows the battery percent of the object. \u00a0Line 15 shows the product that this ioreg object corresponds to. \u00a0Then at the very top you see a line that contains the object name (line 1).<\/p>\n<\/div>\n<div>For more information on the ioreg I\/O kit registry tool in Mac OS X, please see the Mac OS X Manual.<\/div>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" src=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=5fde016f-4ea7-404c-ada7-a0cd49548379\" alt=\"Enhanced by Zemanta\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>There are a few reasons why somebody might want to check the current battery percentage of a bluetooth mouse and\/or keyboard within Terminal on a mac. \u00a0Some that come to mind are for use in GeekTool, if you are connected to the computer remotely through ssh, etc. Well as it turns out, its actually very [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,11],"tags":[17,16,12,15,18,14,13,19],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-command-line","category-mac","tag-apple","tag-battery","tag-bluetooth","tag-geektool","tag-mac-os","tag-mac-os-x","tag-magic-mouse","tag-universal-serial-bus","no-thumb"],"_links":{"self":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/19"}],"collection":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":5,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":454,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/19\/revisions\/454"}],"wp:attachment":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}