I wrote an AppleScript, referred to as with Automator (macOS 14.6, Sonoma, on an M1 Mac). I wrote a code for reminding myself to show off Bluetooth after 120 seconds, whether it is nonetheless on.
I would like some assist to grasp what’s unsuitable. I believe the issue is said to the usage of shell script date +%s
as a quantity for doing algebraic operations.
I am not that acquainted with this coding language so most likely there’s another strategy to go on this identical instructions.
world Cnt
world Cnt2
world Cnt3
world diff
world curTime
world btOnTime
set Cnt to 0
set Cnt2 to 0
set Cnt3 to 0
set btOnTime to do shell script "date +%s"
set curTime to do shell script "date +%s"
set diff to (curTime as integer) - (btOnTime as integer)
set btStatus to 0
repeat
repeat till btStatus = 0
attempt
do shell script "system_Profiler SPBluetoothDataType | grep -i "State: On""
set btStatus to 1
set btOnTime to do shell script "date +%s"
on error
set btStatus to 0
finish attempt
-- delay 110
set Cnt2 to (Cnt2 + 1)
finish repeat
return show alert "BT ON. OUT OF CICLE 1. Cnt2: " & Cnt2
set curTime to do shell script "date +%s"
repeat whereas diff < 120
set curTime to do shell script "date +%s"
set diff to (curTime as integer) - (btOnTime as integer)
set Cnt3 to (Cnt3 + 1)
-- delay 110
finish repeat
return show alert "BT ON. OUT OF CICLE 2. Cnt3: " & Cnt3
if diff > 120 and Cnt = 0 then
-- set recentRestart to (curTime - btOnTime) < 10
-- if not recentRestart then
return show notification "Stupendo, SPEGNI IL BLUETOOTH!!" with title "Bluetooth acceso da un BOTTO"
set Cnt to (Cnt + 1)
-- finish if
finish if
finish repeat