property sunRise : 8* hours + 0 * minutes
property sunSet : 12* hours + 0* minutes
tell (current date)'s time to if (it > sunRise and it < sunSet) then
activate application "iChat"
else
activate application "TextEdit"
end if
But, I want to change the time property according to what moth it is. I tried this, but it does not work. How can a make this work?:
set currentMonth to month of (current date)
if currentMonth is "January" then
set a to 8
set b to 0
set c to 12
set d to 0
end if
property sunRise : a * hours + b * minutes
property sunSet : c * hours + d * minutes
tell (current date)'s time to if (it > sunRise and it < sunSet) then
activate application "iChat"
else
activate application "TextEdit"
end if
get month of (current date) as text
if result is "January" then
set sunRise to timeAsSeconds given hours:8, minutes:0
set sunSet to timeAsSeconds given hours:12, minutes:0
else
set sunRise to timeAsSeconds given hours:7, minutes:0
set sunSet to timeAsSeconds given hours:12, minutes:30
end if
get time of (current date)
if (result > sunRise) and (result < sunSet) then
activate application "iChat"
else
activate application "TextEdit"
end if
on timeAsSeconds given hours:myHours, minutes:myMinutes
return (myHours * hours + myMinutes * minutes)
end timeAsSeconds
And while Bruce’s is the more elegant solution, here’s the front end of what you had fixed:
property a : missing value
property b : missing value
property C : missing value
property d : missing value
set currentMonth to month of (current date) as text
if currentMonth is "January" then
set {a, b, C, d} to {8, 0, 12, 0}
end if
set sunRise to a * hours + b * minutes
set sunSet to C * hours + d * minutes
tell (current date)
if its month is January then
set sunRise to 8 * hours
set sunSet to 12 * hours
else
set sunRise to 7 * hours
set sunSet to 12 * hours + 30 * minutes
end if
tell time to if it > sunRise and it < sunSet then
activate application "iChat"
else
activate application "TextEdit"
end if
end tell