|
|
#1 |
|
MVP
Join Date: Apr 2007
Posts: 1,036
|
AppleScript: Please explain these two commands
I was reading this post, and found the following AppleScript:
Code:
-- Hit the Tab-key delay 1.0 set timeoutSeconds to 2.0 set uiScript to "keystroke tab" my doWithTimeout(uiScript, timeoutSeconds) set timeoutSeconds to 2.0and my doWithTimeout(uiScript, timeoutSeconds)What, exactly, do these commands do? Thanks.
__________________
"You can shear a sheep many times but skin him only once." –T.A. Preston, Sr. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Jul 2007
Location: Vancouver, Canada
Posts: 1,184
|
Well, the first is just the setting of a variable - timeoutSeconds is the variable and it is being set to a value of 2.0. The second is a function that was presumably captured using Automator's Watch Me Do capability. In this case, the doWithTimeout function executes a "tab" keystroke and waits two seconds afterwards before continuing with the rest of the script.
|
|
|
|
|
|
#3 |
|
MVP
Join Date: Apr 2007
Posts: 1,036
|
Okay, thanks. That makes sense.
Just to make sure I'm understanding correctly, Code:
my doWithTimeout(uiScript, timeoutSeconds) Code:
tell application "System Events" to keystroke tab delay 2 Is the "my doWithTimeout()" a single defined function, or is "my" separate from "doWithTimeout()"? If the latter is true, what does "my" do?
__________________
"You can shear a sheep many times but skin him only once." –T.A. Preston, Sr. |
|
|
|
|
|
#4 |
|
Major Leaguer
Join Date: Mar 2006
Location: Colorado, USA
Posts: 303
|
"My" is a reserved word that is used in tell statements to make sure that the handler call is sent to the correct target:
http://developer.apple.com/documenta...0983-CH206-SW1
__________________
[Snow Leopard 10.6] - MacBook Pro / [Tiger 10.4.11] - G4 Digital Audio, G4 mini / [OS 9.2] - G3 MiniTower |
|
|
|
|
|
#5 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 3,315
|
Your functional equivalent is correct, and my refers to the script itself, usually meaning that AppleScript, Standard Additions, or a Scripting Addition should do it, not a tell block in which the command is embedded: Code:
tell application "Finder" set someThing to my Handler(arguments) end tell on Handler(arg) -- do stuff the Finder doesn't know about end Handler
__________________
PPC dual-core G5/2.3, OS X 10.5.8; 17" MBP core 2 duo/2.6, OS X 10.6.1; VMWare Fusion->Win XP |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|