swiftbar / SwiftBar

Powerful macOS menu bar customization tool
https://swiftbar.app
MIT License
2.87k stars 91 forks source link

Sonoma error? #388

Closed theboyler closed 11 months ago

theboyler commented 11 months ago

My plugin - self-programmed - was working fine on Ventura; just installed Sonoma, and I get an error - see screenshot.

I've checked privacy permissions, and Swiftbar has the appropriate permissions, as far as I can tell.

Environment:

melonamin commented 11 months ago

Hard to say without seeing the code of the plugin, can you share it?

I assume you've tested that the script works by itself in the terminal?

theboyler commented 11 months ago

Yes - not tested in terminal but the script runs fine in applescript.

Code is this:

!/usr/bin/osascript

usual swiftbar declarations snipped out...

try
    set {displays, theText, retina, para} to {(do shell script "/opt/homebrew/bin/displayplacer list"), "", "", 24}
    if (text ((offset of ": " in displays) + 2) thru -1 of paragraph 1 of displays as string) is "37D8832A-2D66-02CA-B9F7-8F30A301B230" then set para to 18
    set curres to words 2 thru -1 of paragraph 5 of displays
    repeat with i in paragraphs para thru -5 of displays
        set res to word 4 of i
        set res2 to res
        set thenum to ((text 1 thru ((offset of "x" in res) - 1) of res) as string) as integer
        if thenum is greater than 1500 and res is not equal to curres then
            if character -1 of i is "n" then set {retina, res2} to {"%20scaling:on", res & " (Retina)"}
            set theText to theText & "----  " & res2 & " | sfimage=display sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCIjQUJFQUVDIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?name=SetRes&input=" & res & retina
        end if
    end repeat
on error
    set {curres, theText} to {"2048x1332", ""}
end try
set theimage to "--| image=\"" & (do shell script "defaults read com.daveboyle.cals image") & "\" bash=/Users/daveboyle/Library/Scripts/showwall.sh terminal=false"

set textcol to "white"
if curres contains "2560x1440" then
    if (count of (characters 11 thru -5 of (do shell script "/usr/sbin/screencapture -R27,13,1,1 -t png /Users/daveboyle/Temp/x.png;/opt/homebrew/bin/convert /Users/daveboyle/Temp/x.png sparse-color:") as string)) is 8 then set textcol to "Black"
else
    if (count of (characters 11 thru -5 of (do shell script "/usr/sbin/screencapture -R25,25,1,1 -t png /Users/daveboyle/Temp/x.png;/opt/homebrew/bin/convert /Users/daveboyle/Temp/x.png sparse-color:") as string)) is 8 then set textcol to "Black"
end if

try
    set ssid to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'"
    if ssid is "           SSID: " then
        set wifi to "-- No Wifi | sfimage=wifi.slash sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name="
    else
        set wifi to "-- " & ssid & " | sfimage=wifi sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name="
    end if
on error
    set wifi to "-- No Wifi | sfimage=wifi.slash sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name="
end try

try
    set extip to do shell script "dig +short myip.opendns.com @resolver1.opendns.com"
    if (extip as string) contains "." then
        set thenetwork to "----  " & (do shell script "curl ifconfig.co") & " | sfimage=network sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmx1ZSIsImJsYWNrIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0=
------ Check Speed | sfimage=speedometer sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=Speedtest"
    else
        set thenetwork to "---  No connection | sfimage=point.3.filled.connected.trianglepath.dotted sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?"
    end if
on error
    set thenetwork to "----  No Connection | sfimage=point.3.filled.connected.trianglepath.dotted sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?"
end try
try
    set theRouter to "----  " & (IPv4 address of (get system info)) & " | sfimage=point.3.filled.connected.trianglepath.dotted sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?"
on error
    set my theRouter to "----:app.connected.to.app.below.fill:  No connection | href=http://openshortcut?"
end try

set VPN to false
try
    if (do shell script "scutil --nwi | grep VPN || echo") contains "." then set VPN to true
end try

if VPN is true then
    set VPN to " VPN Connected | sfimage=checkmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9" & return & "-- Disconnect | sfimage=xmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=toggle%20VPN"
else
    if ssid is "           SSID: " then
        set VPN to " VPN Disconnected | sfimage=xmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=toggle%20VPN" & return & "-- Connect | sfimage=checkmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9"
    else
        set VPN to " VPN Disconnected | sfimage=xmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=toggle%20VPN" & return & "-- Connect | sfimage=checkmark.shield sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=toggle%20VPN"
    end if
end if

set networks to VPN & return & wifi & return & "----  Run Network Update... | sfimage=arrow.clockwise.circle.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsid2hpdGUiLCIjRjA4RTAwIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?Check%20Network
" & theRouter & return & thenetwork

set therefresh to " Refresh | sfimage=arrow.triangle.2.circlepath.circle.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsid2hpdGUiLCIjMTQ3RDNEIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=swiftbar://refreshplugin?index=1"

if (do shell script "system_profiler SPNetworkDataType | grep -i 'media subtype'") contains "1000baseT" then
    set ether to true
else
    set ether to false
end if
if (do shell script "tmutil status | grep Running") contains "1" then
    if ether is false then
        set TMstat to " Backup in progress... | sfimage=externaldrive.fill.badge.wifi sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiIzc2QTNBNSJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?"
    else
        set TMstat to " Backup in progress... | sfimage=externaldrive.fill.badge.checkmark sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCIjNzZBM0E1Il0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?"
    end if
else
    set theread to paragraphs 19 thru -6 of (do shell script "/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine Destinations")
    if item ((count of items of theread) - 1) of theread contains ";" then
        set thedate to item ((count of items of theread) - 2) of theread
    else
        set thedate to item ((count of items of theread) - 1) of theread
    end if
    set dnow to (current date)
    set dthen to (current date)
    set {time of dthen, time of dnow, day of dthen, month of dthen, year of dthen} to {0, 0, word 3 of thedate, word 2 of thedate, word 1 of thedate}
    set timegap to (dnow - dthen) / 86400 as integer
    if timegap is 0 and day of dthen is not equal to day of dnow then set timegap to 1
    if (do shell script "system_profiler SPNetworkDataType | grep -i 'media subtype'") contains "1000baseT" then
        set badge to "-- Backup now | sfimage=externaldrive.fill.badge.checkmark sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCIjNzZBM0E1Il0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?name=startTM"
    else
        set badge to "-- Backup now (on wifi) | sfimage=externaldrive.fill.badge.wifi sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiIzc2QTNBNSJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=startTM"
    end if
    if timegap is 0 then set timestat to "Backed up earlier today"
    if timegap is 1 then set timestat to "Backed up yesterday"
    if timegap is greater than 1 then set timestat to "Last backed up " & timegap & " days ago"
    if timegap is greater than 2 then
        set TMstat to " " & timestat & "| sfimage=externaldrive.fill.badge.timemachine sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiIzVDOEY5MCJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=startTM" & return & badge
    else
        set TMstat to " " & timestat & "| sfimage=externaldrive.fill.badge.timemachine sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCIjNUM4RjkwIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?name=startTM" & return & badge
    end if
end if

try
set {displays, theText, retina, para} to {(do shell script "/opt/homebrew/bin/displayplacer list"), "", "", 24}
if (text ((offset of ": " in displays) + 2) thru -1 of paragraph 1 of displays as string) is "37D8832A-2D66-02CA-B9F7-8F30A301B230" then set para to 18
    set curres to words 2 thru -1 of paragraph 5 of displays
    repeat with i in paragraphs para thru -5 of displays
        set res to word 4 of i
        set res2 to res
        set thenum to ((text 1 thru ((offset of "x" in res) - 1) of res) as string) as integer
        if thenum is greater than 1500 and res is not equal to curres then
            if character -1 of i is "n" then set {retina, res2} to {"%20scaling:on", res & " (Retina)"}
            set theText to theText & "----  " & res2 & " | sfimage=display sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCIjQUJFQUVDIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= href=http://openshortcut?name=SetRes&input=" & res & retina
        end if
    end repeat
on error
    set {curres, theText} to {"2048x1332", ""}
end try
set theimage to "--| image=\"" & (do shell script "defaults read com.daveboyle.cals image") & "\" bash=/Users/daveboyle/Library/Scripts/showwall.sh terminal=false"
set wallpaper to " " & striptext((do shell script "defaults read com.daveboyle.cals wallpaper"), "%20", " ") & " | sfimage=photo.artframe sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJncmVlbiJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 " & return & theimage & return & "-- Change Wallpaper | sfimage=arrow.triangle.2.circlepath.circle.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsid2hpdGUiLCJncmVlbiJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=wallpaperchange" & return & "-- Reverse Search | sfimage=text.below.photo.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJ3aGl0ZSJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=Reverse%20Wallpaper%20Search" & return & " " & curres & " | sfimage=display sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCIjQUJFQUVDIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0= " & return & theText

set devices to do shell script "/opt/homebrew/bin/blueutil --connected"
set {pod1, pod2} to {"", ""}
if devices contains "irPods" then
    repeat with i in every paragraph of (do shell script "system_profiler SPBluetoothDataType")
        if i contains "Battery Level" then
            set x to text ((offset of ":" in i) + 2) thru -2 of i
            set charge to (x * 2 div 25 - x div 25) * 25
            if charge is less than 26 then
                set apbatt to " | sfimage=battery." & charge & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ=="
            else
                set apbatt to " | sfimage=battery." & charge & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9"
            end if
            set y to character 15 of i
            if pod1 is "" then
                set pod1 to "-- " & y & ": " & charge & apbatt & " href=http://openshortcut?name=BT&input=disconnect%40-70-f5-ce-2d-a9 tooltip=" & x & "%" & return
            else
                set pod2 to "-- " & y & ": " & charge & apbatt & " href=http://openshortcut?name=BT&input=disconnect%40-70-f5-ce-2d-a9 tooltip=" & x & "%" & return
            end if
        end if
    end repeat
    set pods to pod1 & pod2
else
    set pods to "--Connect Airpods | sfimage=airpodspro sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJncmVlbiJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=connect%40-70-f5-ce-2d-a9"
end if
set charge to ""
if devices contains "adio" then
    set radio to "--Disconnect Radio | sfimage=hifispeaker.2.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJ3aGl0ZSJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=disconnect%40-ef-4c-72-92-fd"
else
    set radio to "--Connect Radio | sfimage=hifispeaker.2.fill sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJ3aGl0ZSJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=connect%40-ef-4c-72-92-fd"
end if
set theText to (do shell script "pmset -g batt" as string)
set level to word 6 of (paragraph 2 of theText) as integer
set remaining to (word 13 of theText & ":" & word 14 of theText) as string
set charge to (level * 2 div 25 - level div 25) * 25
if charge is less than 26 then
    set charge to " | sfimage=battery.25 sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name= "
else
    set charge to " | sfimage=battery." & charge & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name= "
end if
if level is 100 then
    set batttime to "100% (Fully charged)" & charge
else if theText contains "esxtimate" then
    set batttime to level & "% (Calculating time...)" & charge
else if theText contains "not charging" then
    set batttime to level & "% (not charging)" & charge
else if theText contains "AC" then
    set batttime to level & "% (" & remaining & " until charged)" & charge
else if theText contains "Battery Power" then
    set batttime to (level & "% (" & remaining & " left)" & charge) as string
end if
set laptop to "Laptop " & batttime

try
    set {extra, btbatts} to {"", do shell script "ioreg -r -l -n AppleHSBluetoothDevice | egrep '\"BatteryPercent\" = |^  \\|   \"Bluetooth Product Name\" = '"}
    if (count of paragraphs of btbatts) is 4 then
        set mpow to word 5 of (paragraph 4 of btbatts) as integer
        set kpow to word 5 of (paragraph 2 of btbatts) as integer
        set mpow to (mpow * 2 div 25 - mpow div 25) * 25
        set kpow to (kpow * 2 div 25 - kpow div 25) * 25
        if mpow is less than 26 then
            set mouse to "--Disconnect Mouse | sfimage=battery." & mpow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ==  href=http://openshortcut?name=BT&input=disconnect%ac-bc-32-e7-67-2c tooltip=" & mpow & "%"
        else
            set mouse to "--Disconnect Mouse | sfimage=battery." & mpow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9  href=http://openshortcut?name=BT&input=disconnect%ac-bc-32-e7-67-2c tooltip=" & mpow & "%"
        end if
        if kpow is less than 26 then
            set keyb to "--Disconnect Keyboard | sfimage=battery." & kpow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=BT&input=disconnect%c0-a5-3e-09-75-88 tooltip=" & kpow & "%"
        else
            set keyb to "--Disconnect Keyboard | sfimage=battery." & kpow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=disconnect%c0-a5-3e-09-75-88 tooltip=" & kpow & "%"
        end if
        set devices to mouse & return & keyb
    else if (count of paragraphs of btbatts) is 2 then
        set pow to word 5 of (paragraph 2 of btbatts) as string as integer
        set pow to (pow * 2 div 25 - pow div 25) * 25
        if (paragraph 2 of btbatts as string) contains "Mouse" then
            if pow is less than 26 then
                set mouse to "--Disconnect Mouse | sfimage=battery." & pow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ==  href=http://openshortcut?name=BT&input=disconnect%ac-bc-32-e7-67-2c tooltip=" & pow & "%"
            else
                set mouse to "--Disconnect Mouse | sfimage=battery." & pow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9  href=http://openshortcut?name=BT&input=disconnect%ac-bc-32-e7-67-2c tooltip=" & pow & "%"
            end if
            set keyb to "--Connect Keyboard | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=ttp://openshortcut?name=BT&input=connect%c0-a5-3e-09-75-88"
            set devices to mouse & return & keyb
        else
            if pow is less than 26 then
                set keyb to "--Disconnect Keyboard | sfimage=battery." & pow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsicmVkIiwiYmxhY2siXSwgInNjYWxlIjogImxhcmdlIiwgIndlaWdodCI6ICJtZWRpdW0ifQ== href=http://openshortcut?name=BT&input=disconnect%c0-a5-3e-09-75-88 tooltip=" & pow & "%"
            else
                set keyb to "--Disconnect Keyboard | sfimage=battery." & pow & " sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=disconnect%c0-a5-3e-09-75-88 tooltip=" & pow & "%"
            end if
            set mouse to "--Connect Mouse | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=connect%ac-bc-32-e7-67-2c"
            set devices to keyb & return & mouse
        end if
    else
        set mouse to "--Connect Mouse | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=connect%ac-bc-32-e7-67-2c"
        set keyb to "--Connect Keyboard | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=ttp://openshortcut?name=BT&input=connect%c0-a5-3e-09-75-88"
        set devices to mouse & return & keyb
    end if
on error
    set mouse to "--Connect Mouse | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=http://openshortcut?name=BT&input=connect%ac-bc-32-e7-67-2c"
    set keyb to "--Connect Keyboard | sfimage=magicmouse sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiYmxhY2siLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9 href=ttp://openshortcut?name=BT&input=connect%c0-a5-3e-09-75-88"
    set devices to mouse & return & keyb
end try

set power to laptop & return & devices & return & pods & return & radio

set AppleScript's text item delimiters to "\\260"
considering case
    set temporaryList to every text item in (do shell script "defaults read com.daveboyle.cals weather")
end considering
set AppleScript's text item delimiters to "°"
set weather to temporaryList as text

if textcol is "white" then
    set final to "| sfimage=filemenu.and.selection sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiIzkyRjQ5MyIsIndoaXRlIl0sICJzY2FsZSI6ICJsYXJnZSIsICJ3ZWlnaHQiOiAibWVkaXVtIn0="
else
    set final to "| sfimage=filemenu.and.selection sfconfig=eyJyZW5kZXJpbmdNb2RlIjoiUGFsZXR0ZSIsICJjb2xvcnMiOlsiZ3JlZW4iLCJibGFjayJdLCAic2NhbGUiOiAibGFyZ2UiLCAid2VpZ2h0IjogIm1lZGl1bSJ9"
end if

on striptext(str, old, new)
    set AppleScript's text item delimiters to the old
    set the item_list to every text item of str
    set AppleScript's text item delimiters to the new
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end striptext

return final & "
---
" & networks & "
---
" & power & "
---
" & wallpaper & "
---
" & TMstat & return & "---" & return & weather & return & "
---"
theboyler commented 11 months ago

Fixed it - it was that SwiftBar didn't have permission to communicate with Bluetooth (and hadn't asked for it, either). Once I granted it, all was good. Thanks!

melonamin commented 11 months ago

Ok, gald you've figure that out!