How to test if a script is working (renice)

This script displays in the Activity Monitor but how do I test to see if it’s really doing anything.

global PrevAppId
set PrevAppId to 36

on idle {}
	my handleProcesses()
	return 10
end idle

on handleProcesses()
	tell application "System Events"
		set FrontAppId to (get unix id of every process whose frontmost is true)
	end tell
	if FrontAppId is not PrevAppId then
		do shell script "renice 19 " & PrevAppId & " > /dev/null 2>&1 &"
		do shell script "renice -20 " & FrontAppId password "your paswword" with administrator privileges
		set PrevAppId to FrontAppId
	else
		set PrevAppId to FrontAppId
	end if
end handleProcesses

Tom

Browser: Safari 528.16
Operating System: Mac OS X (10.5)

One way is using the say command

global PrevAppId
set PrevAppId to 36
set debug to true
on idle {}
	
	my handleProcesses(debug)
	return 10
end idle

on handleProcesses( debug)
	if debug then say "running handler"
	tell application "System Events"
		if debug then say "getting unix i d"
		set FrontAppId to (get unix id of every process whose frontmost is true)
		if debug then say ("unix i d, " & FrontAppId)
	end tell
	if FrontAppId is not PrevAppId then
		if debug then say "FrontAppId is not PrevAppId"
		if debug then say "Doing renice 19 "
		do shell script "renice 19 " & PrevAppId & " > /dev/null 2>&1 &"
		if debug then say "Doing renice 20 "
		do shell script "renice -20 " & FrontAppId password "your paswword" with administrator privileges
		if debug then say "setting PrevAppId to FrontAppId "
		set PrevAppId to FrontAppId
	else
		if debug then say "FrontAppId is PrevAppId"
		set PrevAppId to FrontAppId
	end if
	if debug then say "Going to idle"
end handleProcesses

Re added the (debug) bit which I accidently took out :confused:

Thank you, Mark.

Tom

Another option is to write to the console.

logger [-is] [-f file] [-p pri] [-t tag] [message …]

Logger provides a shell command interface to the syslog(3) system log
module.

 Options:

 -i       Log the process id of the logger process with each line.

 -s       Log the message to standard error, as well as the system log.

 -f file  Log the specified file.

 -p pri   Enter the message with the specified priority.  The priority may
          be specified numerically or as a ``facility.level'' pair.  For
          example, ``-p local3.info'' logs the message(s) as informational
          level in the local3 facility.  The default is ``user.notice.''

 -t tag   Mark every line in the log with the specified tag.

 message  Write the message to log; if not specified, and the -f flag is
          not provided, standard input is logged.

I personally favor the file log method because it gives you a time check as well as a rundown on what was done.

James and Adam,

Thank you for your input. Another option - great.

Tom

Browser: Safari 528.16
Operating System: Mac OS X (10.5)