Re: AppleScript-Users Digest, Vol 4, Issue 2
Re: AppleScript-Users Digest, Vol 4, Issue 2
- Subject: Re: AppleScript-Users Digest, Vol 4, Issue 2
- From: Christopher Nebel <email@hidden>
- Date: Tue, 2 Jan 2007 13:59:55 -0800
On Jan 2, 2007, at 11:41 AM, Mark J. Reed wrote:
On 1/2/07, Bryan Lockwood <email@hidden> wrote:
Perhaps I'm just not yet steeped enough in AppleScript, but the
following
snippet, taken from a recent digest, leaves me totally nonplussed.
How in the devil am I supposed to parse the line below which reads
" tell
Finder window 1 to if exists then". I don't get this at all
(although, of
course, I can figure out what it means, it seems to me totally
ungrammatical. Wish I had a yacc grammar for AppleScript, but I
know it's
impossible.) This makes split infinitives look beautiful. Anyhow,
so much
for readibility.
AppleScript ain't English. It just tries to be. :)
tell Foo to Bar
is just a shortcut to avoid creating a tell block. It's semantically
identical to
tell Foo
Bar
end tell
In either case, the default argument for any message is the recipient
of the tell block, so "exists" by itself in a tell to window 1 asks if
window 1 exists. I think this is equivalent:
tell application "Finder"
if window 1 exists then
...
end if
end tell
Strictly speaking, "tell x to exists" is equivalent to "tell x; exists
it", where "it" refers to the current "tell" target. Expanding "it",
you'd get what Mark wrote above.
The single-line "tell" variant reads great for simple commands --
"quit", for example. However, the grammar allows any statement to
follow the "to", so an "if" is perfectly valid, if not especially
readable. Most languages have this problem, if you want to consider
it a problem. You can write unreadable code in just about any
language; that doesn't mean that you have to. (However, see <http://www.gnu.org/fun/jokes/unix-hoax.html
>.)
Incidentally, a yacc grammar for AppleScript is perfectly do-able.
It's built using yacc, in fact. The problem is the lexical phase --
determining what sequence of tokens constitute a single "identifier"
is a bit of a trick, especially since the rules change as you parse.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden