Adam,
I’m not sure if you were joking about the “beep/display dialog” example . But to really see the difference in execution speed, try the “resize window” example. Save the code below as an applet and execute it with Finder (double-click). You’ll find that it executes quickly. Now change the line “run script the_script” to “run the_script”, resave it as an applet, execute it again with Finder, and you’ll see how slowly it executes. Another way to get it to execute slowly, as Nigel and I have been observing, is to remove the lines “run script the_script”, “script the_script”, and “end script”; ie, remove the script object, and convert it to vanilla code. Once again, save it as an applet, and execute it with Finder. Slow!!! The common theme to all this is: for fast execution speed, an applet must be executed by “run script” (or by clicking the Run command in Script Editor, which I presume does the same thing as “run script”).
bmose
-- CREATE A SAMPLE TEXTEDIT DOCUMENT
tell application "TextEdit"
activate
make new document with properties {text:"Newton's Three Laws of Motion:
I. Every object in a state of uniform motion will remain in that state of motion ...
II. Force equals mass times acceleration.
III. For every action there is an equal and opposite reaction."}
end tell
-- RESIZE THE WINDOW
run script the_script
script the_script
tell application "System Events" to tell process "TextEdit"
set frontmost to true
tell window 1
tell scroll area 1 to if exists scroll bar 2 then keystroke "w" using {command down, shift down} -- if the window opens in "Wrap to Page" mode, change to "Wrap to Text"
click (first button whose subrole is "AXZoomButton") -- start with a fully zoomed window
set {x_max, y_max} to size -- get the starting size of the fully zoomed window
repeat with xy_axis in {"y", "x"} -- resize the vertical then the horizontal dimension of the window
if contents of xy_axis is "x" then -- set the maximum and minimum amounts (delta) by which the window will be resized with each iteration, as well as switches to apply the resizing to the horizontal or vertical dimension selectively
set {delta_max, delta_min, x_delta_switch, y_delta_switch} to {-x_max / 2, 10, 1, 0}
else if contents of xy_axis is "y" then
set {delta_max, delta_min, x_delta_switch, y_delta_switch} to {-y_max / 2, 10, 0, 1}
end if
set delta_value to delta_max -- set the starting delta to 1/2 the dimension of the fully zoomed window
repeat
set abs_delta_value to delta_value * (1 - 2 * ((delta_value < 0) as integer)) -- absolute value of delta
tell scroll area 1 to tell scroll bar 1 to if enabled then -- if scroll bar is enabled, window size is too small
if delta_value = delta_max then exit repeat -- quit if fully zoomed window is too small
if delta_value < 0 then set delta_value to delta_value * -1 -- otherwise, be sure the next window resizing is in the optimal direction
else -- if scroll bar is not enabled, window size is either optimal or too big
if abs_delta_value < delta_min then exit repeat -- quit if window size is optimal
if delta_value > 0 then set delta_value to delta_value * -1 -- otherwise, be sure the next window resizing is in the optimal direction
end if
set {x, y} to size
set size to {x + delta_value * x_delta_switch, y + delta_value * y_delta_switch} -- resize the window
if abs_delta_value > delta_min then set delta_value to delta_value / 2 -- halve the amount by which the window will next be resized, but no smaller than the minimum amount
end repeat
end repeat
set {x, y} to size
set position to {round (x_max - x) / 2 rounding down, round (y_max - y) / 2 rounding down} -- center window on screen
end tell
end tell
end script