Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 07-04-2008, 02:35 AM   #1
J Christopher
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)
Could someone please explain:
set timeoutSeconds to 2.0
and
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.
J Christopher is offline   Reply With Quote
Old 07-04-2008, 03:20 AM   #2
wdympcf
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.
wdympcf is offline   Reply With Quote
Old 07-04-2008, 04:40 AM   #3
J Christopher
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)
is the functional equivalent (in this particular case) to

Code:
tell application "System Events" to keystroke tab
delay 2
Is this correct?

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.
J Christopher is offline   Reply With Quote
Old 07-04-2008, 01:43 PM   #4
Red_Menace
Major Leaguer
 
Join Date: Mar 2006
Location: Colorado, USA
Posts: 308
"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.2] - MacBook Pro / [Tiger 10.4.11] - G4 Digital Audio, G4 mini / [OS 9.2] - G3 MiniTower
Red_Menace is offline   Reply With Quote
Old 07-04-2008, 02:44 PM   #5
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 3,330
Quote:
Originally Posted by J Christopher
Okay, thanks. That makes sense.

Just to make sure I'm understanding correctly,

Code:
my doWithTimeout(uiScript, timeoutSeconds)
is the functional equivalent (in this particular case) to

Code:
tell application "System Events" to keystroke tab
delay 2
Is this correct?

Is the "my doWithTimeout()" a single defined function, or is "my" separate from "doWithTimeout()"? If the latter is true, what does "my" do?

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.2; VMWare Fusion->Win XP
NovaScotian is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:07 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.