subroutines and tell blocks

I’m having trouble with calling subroutines. Is it just common knowledge and a newbie mistake that you can’t do this, or am I doing it wrong? I’m using a subroutine to write to a log file, which works great - unless it’s within a tell block. It’s not really a big deal since I was mostly using it for troubleshooting a very long script, but it would be nice to understand.

For instance something along the lines of


tell applications "QuarkXPress"
activate
WriteLog("Quark was activated")
end tell

errors out the script

or for an actual example from the script:


tell application "GrowlHelperApp"
--	Send a Notification...
notify with name  "EPSed" title "Quark File EPSed" description DocName & " has been saved as EPS to Archive:EPS ADS" application name "Quark EPS" image from location icon_file
WriteLog("Growl sent a notification")					
end tell

The code above errors and quits, but if I move the Writelog line outside the tell block, it works and continues on with the script.

Try

tell application "QuarkXPress"
    activate
    my WriteLog("Quark was activated")
end tell

Make sure you put “my” in front of “WriteLog” when it’s inside a tell block. Otherwise it’s telling finder to call a subroutine it’s never heard of.

Ah! Good to know. Thank you. I need to spend some more time in the tutorials, apparently.

Better:

tell application "QuarkXPress"
	activate
end tell
WriteLog("Quark was activated")

or easier:


activate application "QuarkXPress"
WriteLog("Quark was activated")

It’ s good programming (or scripting) habit to avoid any “strange” code in application tell block, if possible

The problem arose because there were multiple things I was telling Quark to do, that I wanted in the log. For instance, I wanted to know when it activated, successfully opened the file, and when the file was saved as an EPS. Some of those were even within a “tell document” block within the “tell Quark” block. For just one action, sure, outside the block works fine and is a better solution, but without writing 6 different tell blocks for the same document just to write in logging capabilities, it seems better to have a way to do it within the tell blocks. At least to my fuzzy brain logic.