... doesn't understand the message

Hi, I have this code as part of an iChat auto-response script…

property comLib : missing value
property mediaLib : missing value
property utilsLib : missing value
set my scriptLoc to ":Library:Scripts:iChat:Script Plugins:"

set my comLib to load script file (my scriptLoc & "Communication.scpt")
set my mediaLib to load script file (my scriptLoc & "Media.scpt")
set my utilsLib to load script file (my scriptLoc & "Utilities.scpt")

on process(message)
if message contains "battery" then
        set re to my utilsLib's batteryStat("MacBook Pro")
    else if message contains "mail" then
        set re to my comLib's unreadMail()
    else
        
        set re to "Command " & quoted form of message & " was not understood"
        
    end if
    return re
end process

using terms from application "iChat"
	
	on message received theMessage from theBuddy for theChat
		
		try
			
			set theResponse to load(theMessage)
			
			send theResponse to theBuddy
			
		on error (errMsg)
			send "Unfortunately, an error was encountered:" & return & errMsg to theBuddy
			
		end try
		
	end message received
	
end using terms from

… however, if I send a message to the iChat account that is hooked up to run this, I just get a message back saying “Unfortunately, an error was encountered:
comLib doesn’t understand the unreadMail message.” and I can’t understand why!

Inside Communication.scpt I have the unreadMail handler and if I comment out the iChat part of the original auto-response script (above), add in

display dialog "Command to test: " default answer ""
set theMessage to the text returned of the result
set theResponse to load(theMessage)
display dialog theResponse 

and run it in script editor, it sort of works… I get an error from the “scriptLoc” part… the error I get is "error “Can’t make scriptLoc into type reference.” number -1700 from scriptLoc to reference
"

Any help would be appreciated! :slight_smile:

Your variable names are bad. Variables can only be one word. You have variables such as “my scriptLoc”. That’s 2 words so it won’t work. Either remove the word “my” from the variable or join them using “_” such as “my_scritLoc”.

.is no valid path. HFS paths start always with a disk name.
A leading colon is never a replacement for the leading slash in POSIX paths
Or use a relative path

set scriptLoc to ((path to scripts folder as text) & "iChat:Script Plugins:")

Thanks very much guys! @regulus6633 I actually thought that when you were talking about a property that you had defined earlier, you had to put “my” before it…

Nope. You only use “my” to refer to commands, not variables. For example, suppose you created a subroutine called “on doSomething()” in your script. Normally in your code you can use that handler using its name doSomething(). However, if you wanted to call that handler from within a “tell” block of code you’d need “my”. For instance if you were in a tell application “Finder” block. If you used doSomething() in that then you would be telling the Finder to doSomething(), so the Finder would search itself for the doSomething() command. Of course the Finder doesn’t have that command so you would get an error. As such if you used “my doSomething()” in the Finder tell block then you are telling the Finder that the script (i.e. my) owns the doSomething() command. So the Finder would ask the script to doSomething() instead of trying to do it itself.

So “my” and a variable never go together. You can use “my” before a command to specify that the command belongs to the script.

I think I understand now :slight_smile: