why does this script keep repeating itself?

I dont know if I should post this here or under my previous post…but here it is. This script will start 1 of 2 apps that I made, based on the month and time. The script works great. However, it keeps looping the activation of the program at the end. To make matters more weird, it does not have this problem if I put normal app, like ichat and itunes in it. Otherwise, it just keeps telling the app to activate when it is done doing its thing. here are my questions:

  1. Do you know why this would loop? Is it something in the way I saved my 2 apps?
  2. Is there a way to shut this script off immediatly once it tells the program to activate?
set theMonth to month of (current date) as text
if theMonth is "January" then
	set sunRise to timeAsSeconds given hours:7, minutes:20
	set sunSet to timeAsSeconds given hours:17, minutes:35
end if
if theMonth is "Febuary" then
	set sunRise to timeAsSeconds given hours:7, minutes:15
	set sunSet to timeAsSeconds given hours:18, minutes:5
end if
if theMonth is "March" then
	set sunRise to timeAsSeconds given hours:6, minutes:40
	set sunSet to timeAsSeconds given hours:18, minutes:35
end if
if theMonth is "April" then
	set sunRise to timeAsSeconds given hours:8, minutes:0
	set sunSet to timeAsSeconds given hours:19, minutes:30
end if
if theMonth is "May" then
	set sunRise to timeAsSeconds given hours:6, minutes:25
	set sunSet to timeAsSeconds given hours:20, minutes:30
end if
if theMonth is "June" then
	set sunRise to timeAsSeconds given hours:6, minutes:15
	set sunSet to timeAsSeconds given hours:12, minutes:0
end if
if theMonth is "July" then
	set sunRise to timeAsSeconds given hours:6, minutes:20
	set sunSet to timeAsSeconds given hours:20, minutes:45
end if
if theMonth is "August" then
	set sunRise to timeAsSeconds given hours:6, minutes:45
	set sunSet to timeAsSeconds given hours:20, minutes:20
end if
if theMonth is "September" then
	set sunRise to timeAsSeconds given hours:7, minutes:15
	set sunSet to timeAsSeconds given hours:19, minutes:40
end if
if theMonth is "October" then
	set sunRise to timeAsSeconds given hours:7, minutes:15
	set sunSet to timeAsSeconds given hours:18, minutes:45
end if
if theMonth is "November" then
	set sunRise to timeAsSeconds given hours:7, minutes:10
	set sunSet to timeAsSeconds given hours:17, minutes:20
end if
if theMonth is "December" then
	set sunRise to timeAsSeconds given hours:7, minutes:35
	set sunSet to timeAsSeconds given hours:17, minutes:15
end if
-----------------------------------------------
get time of (current date)
if (result > sunRise) and (result < sunSet) then
	activate application "Daylight scc"
else
	activate application "nightime scc"
end if
on timeAsSeconds given hours:myHours, minutes:myMinutes
	return (myHours * hours + myMinutes * minutes)
end timeAsSeconds

Hi,

To run your script app, use the launch command first:

tell application “ScriptAppName”
launch
run
end tell

According to the document, there is an implicit run sent from the tell app statement. This causes a problem when the second run is sent. You can read about it AppleScriptLanguageGuide. Search for launch.

gl,

Thanks! Does thins look trouble free to you? Is there anything that could be improved? I am not getting any errors with the ignoring statement. This is alot cleaner! Ian

 set MySettings to {{7, 20, 17, 35}, {7, 15, 18, 5}, {6, 40, 18, 35}, {8, 0, 19, 30}, {6, 25, 20, 30}, {6, 15, 12, 0}, {6, 20, 20, 45}, {6, 45, 20, 20}, {7, 15, 19, 40}, {7, 15, 18, 45}, {7, 10, 17, 20}, {7, 35, 17, 15}}

set {a, b, c, d} to item (month of (current date) as number) of MySettings
set sunRise to timeAsSeconds given hours:a, minutes:b
set sunSet to timeAsSeconds given hours:c, minutes:d
get time of (current date)
if (result > sunRise) and (result < sunSet) then
	ignoring application responses
		tell application "Daylight scc" to run
	end ignoring
else
	ignoring application responses
		tell application "nightime scc" to run
	end ignoring
	
	
end if

on timeAsSeconds given hours:myHours, minutes:myMinutes
	return (myHours * hours + myMinutes * minutes)
end timeAsSeconds

A couple of minor points might be worth considering, Ian.

For greater efficiency, you could avoid performing some calculations at runtime by pre-calculating the seconds in the variable MySettings.

It’s also worth bearing in mind that external calls (to applications, scripting additions or the shell, for instance) carry a time penalty - so it’s a good idea to keep them to a minimum. For example, instead of:

set theMonth to month of (current date)
set theTime to time of (current date)

… you could say:

set theDate to (current date)
set theMonth to month of theDate
set theTime to time of theDate

… which, since it makes only one call to Standard Additions, is nearly twice as fast. Or you could use this (even slightly faster) variation:

tell (current date)
	set theMonth to its month
	set theTime to time
end tell

Finally, if you’re going to use an explicit run command, consider kel’s advice about preceding such calls with a launch statement. In particular, you might want to check out what the AppleScript Language Guide has to say about calling a script application from a script.

Taking these points into account, your script might look something like this:

set MySettings to {{26400, 63300}, {26100, 65100}, {24000, 66900}, {28800, 70200}, {23100, 73800}, {22500, 43200}, {22800, 74700}, {24300, 73200}, {26100, 70800}, {26100, 67500}, {25800, 62400}, {27300, 62100}}

tell (current date)
	set {sunRise, sunSet} to item (its month as integer) of MySettings
	tell time to if it > sunRise and it < sunSet then
		set appName to "Daylight scc"
	else
		set appName to "nightime scc"
	end if
end tell

launch application appName
run application appName

thanks! those are some tungs I would have never know. It is working great! Ian