on 2013-03-03 9:33 LuKreme wrote
Oh, now that is clever.
if i were really clever i'd have already written a Safari extension, but thanks
for the close look
One note on your script (OK, two), since you don't use the_windows variable,
why not replace
set the_windows to every window
repeat with w in the_windows
with
repeat with w in every window
that would work fine in this case; the form i used is just a safe habit coming
from two notions: first, my idiom avoids re-executing "get every window" on
each pass, but does more list traversal; sending Apple Events used to be a lot
slower, but i still write scripts (mostly in py-appscript now) that need
optimization; looking at the event log, my construct sends an event like this:
get id of window id 113513
where your suggestion sends
get id of item 2 of every window
performance on the latter might or might not be as good — it depends somewhat
on the target application's implementation of selectors
also, i have found many cases where assigning the result of a get before
"using" it happily coerces the result; this avoids intractable errors that
sometimes occur when an Apple Event is embedded in a complex expression; i seem
to run into this most in py-appscript, and again, i blame this is on quirks in
the Apple Events implementations of various apps
and, logically, in the run handler
if the result is false then
return
else
… rest of block
philosophically, i use "early exits" a lot to save time and avoid excess
structure (depending on the language, too); however since i have only one early
exit here, what i did seems superfluous; maybe there were some other tests
there before, but now it might as well be:
if the_choice is not false then
… rest of block
("is not false" is not the pointless double negative that it seems; it avoids a
type error)
_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk