Friday, May 27, 2022

#1 2022-05-14 12:38:53 pm

One208
Member
Registered: 2021-03-15
Posts: 57

Airpods Battery

Hi Got this script for another forum to check airpods charge status, the script wud not compile

Syntax error → Expected “given”, “with”, “without”, other parameter name, etc. but found “:”.


set infoDict to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(missing value))



Applescript:


getAirPodsProBatteryLevel("One's AirPods Pro") -- change with your device name

on getAirPodsProBatteryLevel(deviceName)
   set xmlData to do shell script "system_profiler SPBluetoothDataType -xml"
   set theData to ((current application's NSString's stringWithString:xmlData)'s dataUsingEncoding:(current application's NSUTF8StringEncoding))
   set infoDict to (current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(missing value))
   set devlist to ((infoDict's firstObject()'s valueForKey:"_items")'s firstObject()'s valueForKey:"device_connected")
   if devlist ≠ missing value then
       repeat with j from 0 to (count of (devlist as list)) - 1
           if (devlist's objectAtIndex:j)'s allKeys()'s firstObject() as text = deviceName then
               set devDic to ((devlist's objectAtIndex:j)'s valueForKey:deviceName)
               set BatteryCase to (devDic's valueForKey:"device_batteryLevelCase") as string
               set BatteryLeft to (devDic's valueForKey:"device_batteryLevelLeft") as string
               set BatteryRight to (devDic's valueForKey:"device_batteryLevelRight") as string
               return {BatteryCase:BatteryCase, BatteryLeft:BatteryLeft, BatteryRight:BatteryRight}
           end if
       end repeat
   end if
end getAirPodsProBatteryLevel


Filed under: AppleScriptObjC, airpod

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)