This has not always been the case, but in OS X 10.6.8
The following (certainly with OmniFocus and TextEdit, I suspect with other apps too) raises error -30002
-- WORKS IF RUN AFTER THE FOLLOWING CODE,
-- BUT FAILS IF RUN BEFORE IT, OR IN A SCRIPT ON ITS OWN
tell application "TextEdit"
tell front document
current date
end tell
end tell
-- ALWAYS WORKS
tell application "TextEdit"
set oDoc to front document
tell oDoc
current date
end tell
end tell
whereas, the following (sequence reversed) raises no error …
-- ALWAYS WORKS
tell application "TextEdit"
set oDoc to front document
tell oDoc
current date
end tell
end tell
-- WORKS IF RUN AFTER THE PRECEDING CODE,
-- BUT FAILS IF RUN BEFORE IT, OR IN A SCRIPT ON ITS OWN
tell application "TextEdit"
tell front document
current date
end tell
end tell
Other scripts seem to be throwing errors under Lion if reference to a front window or window whose index is 1 is included in Applescript.
current date belongs to Standard Additions, not to TextEdit.
It’s strongly recommended for ages to keep Scripting Addition commands out of any application tell block.
Snow Leopard and also Lion are just less tolerant for these syntax issues than prior system versions
You feel that decreased tolerance explains the asymmetric sequencing issue ? Well, maybe …
( There seems to be some particular association with Script Debugger, incidentally … )
The lion cub is clearly still in diapers, so I’ll keep that at arms length for a while, but I wonder whether its full screen mode creates a special case for applescript access to the windows collection of applications.
No, I regard the “inappropriate” use of a Scripting Addition command a possible cause of the problem.
Does the code behave the same way with code of TextEdit?
Mark Alldritt at Late Night Software reports that he can reproduce this with Script Debugger 4.5, and that it is resolved in current builds of Script Debugger 5.0, which is slated for release late this year.
Since when and why? It follows the parenting chain so an application can overrule a command but it sometimes you want standard addition commands inside an tell application block. Not so long ago the activate command was part of the standard addition command and how about telling an application to show a dialog or alert today? Those commands needs to be inside a tell block.
At least since Tiger launch, activate, reopen and quit are Application commands which belong directly to AppleScript.
These commands can be used as a verb before the application keyword e.g
In Snow Leopard it’s crucial but also in prior AppleScript versions it was recommended and good programming habit to avoid Scripting Addition commands in application tell blocks
I didn’t want to start a discussion, I just wanted to yiam-jin-qui know that this rule isn’t there for ages and that it also doesn’t apply for all commands in the standard addition.
It’s still not crucial but Apple advise it to avoid multi-messaging in your script because every message has a security check every time it’s target changes. So when there is a target in between with other privileges the system throws an error.
I agree it’s more elegant and create better performance but for local script’s like current date in a tell block shouldn’t give an error at all. Also error -30002 is for as far as I know an mac locale error which leads me to my second post about the language settings of the system.
Thanks to both - interesting points, and a more concrete sense of what is going on under the hood than I have previously had.
I was using an English locale, and I’ve seen it on US and UK settings.
Couldn’t immediately get rid of it by logging in with Nederlands dragged up to first place in the language preference list and Nederland as the region for formats, but that may not exclude locale issues - I switch regularly between three main input languages, and occasionally switch locales, and I notice that software (installers particularly) sometimes appear confused about what my current locale actually is.
As Mark Alldritt seems to have fixed it for SD 5.0, I imagine that he has found out what it is.