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 mistaken. I feel the issue is expounded to the usage of shell script date +%s
as a quantity for doing algebraic operations.
I am not that aware of this coding language so in all probability there’s another approach to go on this identical instructions.
international Cnt
international Cnt2
international Cnt3
international diff
international curTime
international 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
strive
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 strive
-- 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