"path to desktop" set at compile time

Hi all!

I’m having an issue with a script I’ve set up for my mother to watch for my brother who is in Iraq to show up on iChat during the day, so she knows he’s still alive. The only problem is that I’ve compiled it into an application so she can just leave it running, but she gets an errors that says “File [path removed]:iChatWatcherLog.txt wasn’t found” with the path to my desktop. This even though I’m using the “path to desktop” feature in the actual script. My best guess is that variable is being hard-coded at compile time, so it doesn’t calculate the path to her desktop.

Any suggestions or ideas to fix this issue? Code is as follows:


property was_online : {}
property watch_list : {}
property filePath : (((path to desktop) as string) & "iChatWatcherLog.txt")

set was_online to check_ichat()
set watch_list to {"Name Here"}

on idle
	set is_online to check_ichat()
	repeat with x in is_online
		copy contents of x to y
		ignoring case, expansion and white space
			if y is not in was_online and y is in watch_list then
				set fileRef to open for access filePath with write permission
				write (return & y & " came online on " & (current date)) to fileRef starting at eof
				close access fileRef
			end if
		end ignoring
	end repeat
	set was_online to is_online
	return 10
end idle

to check_ichat()
	tell application "iChat" to name of accounts of service 1 whose status is not offline
end check_ichat

Thanks! :slight_smile:

-Talix

P.S. I’m running OS 10.4, I believe she is on 10.3, though. Possibly even 10.2. It just occurred to me that that may be part of the issue.

Hi Talix,

You’re right. script properties are set at compile time. Just set the variable in the run handler. The run handler is ususally used for initialization anyway. Also, declare a global variable so your idle handler can see it:

property …
property …
global filePath

gl,

Hello

You may do exactly what you did for the two other properties.


property was_online : {}
property watch_list : {}
property filePath : ""

set filePath to (((path to desktop) as string) & "iChatWatcherLog.txt")
set was_online to check_ichat()
set watch_list to {"Name Here"}

Yvan KOENIG (from FRANCE dimanche 24 décembre 2006 16:32:25)

Thank you both! That did indeed work, although the script as a whole seems to be doing nothing on my mother’s computer, despite it working on mine. :stuck_out_tongue: Maybe it’s something to do with her running OS 10.3.9 instead of 10.4.x like I am…