Usando AppleScript para controlar minhas geringonças...
Este Applescript é compilado como um
applicativo:
(*
Applescript escrito por
Bernardo Höhl em 19 de Julho de 2004.
Este Applescript controla o
dispositivo warrior tocando a campainha de minha
fábrica.
*)
if
((current
date)
as
text)
contains
"Saturday"
or
((current
date)
as
text)
contains
"Sunday"
then
--display
dialog "Quitting!" giving up after 3
tell
me
to
quit
return
else
tell
application
"IOWarriorAppleScriptGateway"
--Aqui
eu declaro minhas variáveis:
set
thePin
to
17
set
theDelay
to
4
set
RepeatInt
to
10
set
theMessage
to
"Erro!"
--
A função que escreve no display:
--
Primeiro vamos definir a mensagem, conforme o
horário:
if
time
of
(current
date) > 0
and
time
of
(current
date) < 28200
then
-- alerta
manhã!
set
theMessage
to
" Alerta Entrada "
else
if
time
of
(current
date) > 28200
and
time
of
(current
date) < 30600
then
--
manhã!
set
theMessage
to
"++++ Entrada ++++"
else
if
time
of
(current
date) > 30600
and
time
of
(current
date) < 45000
then
-- alerta
almoço!
set
theMessage
to
" Alerta Almoco "
else
if
time
of
(current
date) > 45000
and
time
of
(current
date) < 47000
then
-- saida
almoço!
set
theMessage
to
"+ Almoco Saida +"
else
if
time
of
(current
date) > 30600
and
time
of
(current
date) < 45000
then
-- alerta
almoço!
set
theMessage
to
" Alerta Almoco "
else
if
time
of
(current
date) > 49500
and
time
of
(current
date) < 50760
then
-- entrada
almoco!
set
theMessage
to
" Almoco Entrada "
else
if
time
of
(current
date) > 50760
and
time
of
(current
date) < 57600
then
-- Pausa
tarde!
set
theMessage
to
"+ Pausa Tarde +"
else
if
time
of
(current
date) > 57600
and
time
of
(current
date) < 63600
then
-- alerta
tarde!
set
theMessage
to
"Alerta Saida "
else
if
time
of
(current
date) > 63600
then
--and time of (current
date) < 64200 then -- saida tarde!
set
theMessage
to
"++++ Saida ++++"
end
if
my
DisplayMessage("Toque
de Cigarra" &
theMessage)
--Atraze
um pouquinho, assim você pode ler a mensagem:
delay
2
repeat
RepeatInt
times
my
DisplayMessage(theMessage
& "++++ Prim!! ++++")
if
value
of
pin
thePin
is
0 then
set
value
of
pin
thePin
to
1
--say
"turning off"
else
set
the
value
of
pin
thePin
to
0
--say
"turning on"
end
if
delay
theDelay
my
DisplayMessage("
")
end
repeat
--beep
my
DisplayMessage("Controlador
em descanso....")
return
value
of
every
pin
end
tell
end
if
on
DisplayMessage(frase)
--
This part just adds spaces to the end of your frase, in case it is shorter than
16 chars:
repeat
while
true
if
(the
count
of
frase)
< 32
then
set
the
frase
to
frase
& " " --space char,
replace this for any char as you wish.
else
exit
repeat
end
if
end
repeat
set
CharList
to
{}
as
list
set
theItem
to
1
repeat
with
i
from
1
to
the
count
of
frase
--
aqui você pega o caracter que reprensenta "º" e converte para o numero
certo:
if
the
(ASCII
number
of
character
theItem
of
frase)
is
188 then
set
CharList
to
CharList
& 223
as
list
else
set
CharList
to
CharList
& (ASCII
number
of
character
theItem
of
frase)
as
list
end
if
set
theItem
to
theItem +
1
end
repeat
tell
application
"IOWarriorAppleScriptGateway"
--
This line initializes the display:
WriteInterface1
reportId 4
byte0
1
--
This line cleans the display before writing anything :
WriteInterface1
reportId 5
byte0 3
byte1 56
byte2 1
byte3
15
try
WriteInterface1
reportId 5
byte0 134
byte1
(item 1
of
CharList)
byte2
(item 2
of
CharList)
byte3
(item 3
of
CharList)
byte4
(item 4
of
CharList)
byte5
(item 5
of
CharList)
byte6
(item 6
of
CharList)
WriteInterface1
reportId 5
byte0 134
byte1
(item 7
of
CharList)
byte2
(item 8
of
CharList)
byte3
(item 9
of
CharList)
byte4
(item 10
of
CharList)
byte5
(item 11
of
CharList)
byte6
(item 12
of
CharList)
WriteInterface1
reportId 5
byte0 134
byte1
(item 13
of
CharList)
byte2
(item 14
of
CharList)
byte3
(item 15
of
CharList)
byte4
(item 16
of
CharList)
--byte5 (item 13 of
CharList) byte6 (item 14 of CharList)
--This
Line initializes the second part of the display:
WriteInterface1
reportId 5
byte0 1
byte1
168
--Actually
writing the second part of the display:
WriteInterface1
reportId 5
byte0 134
byte1
(item 17
of
CharList)
byte2
(item 18
of
CharList)
byte3
(item 19
of
CharList)
byte4
(item 20
of
CharList)
byte5
(item 21
of
CharList)
byte6
(item 22
of
CharList)
WriteInterface1
reportId 5
byte0 134
byte1
(item 23
of
CharList)
byte2
(item 24
of
CharList)
byte3
(item 25
of
CharList)
byte4
(item 26
of
CharList)
byte5
(item 27
of
CharList)
byte6
(item 28
of
CharList)
WriteInterface1
reportId 5
byte0 134
byte1
(item 29
of
CharList)
byte2
(item 30
of
CharList)
byte3
(item 31
of
CharList)
byte4
(item 32
of
CharList)
end
try
end
tell
end
DisplayMessage
Posted at 11:47 AM