Re: apply the same property to a number of items
Re: apply the same property to a number of items
- Subject: Re: apply the same property to a number of items
- From: "email@hidden" <email@hidden>
- Date: Wed, 23 Feb 2011 20:39:48 -0800
> So, handlers are what is otherwise called subroutines/functions ? That's actually what I think I was looking for.
>
Yes, a handler is the same as a subroutine/function.
> Now, how should I go about that in terms of language and delivery media ? Should I mostly think in terms of Applescript or should I consider diving into about Obj-C ? Would that have to be an "osax" ?
The script I provided was in two parts, the top level script and a handler.
All the top level did was allow the user to select a list of aliases.
Then display the first item in a list.
The handler call is the line that reads:
my SetLablelIndes(listOfFolders)
The parameter for this handler is the variable listOfFolders, and that gets passed to the handler.
At runtime when the script reaches that line execution shifts to the handler which uses the parameter.
When the handler is finished executing, it can send a value back to the script (or not) and the script continues execution.
One of the nice things about handlers is that you can right a generic handler that can be called from various points of your script.
Here's the sample I provided again, along with another version that illustrates more of the functionality of handlers:
------------------
--top level
set listOfFolders to choose folder with prompt "Pick folders to work with" with multiple selections allowed
-- should work with any list of aliases
tell application "Finder" to reveal item 1 of listOfFolders
--this line calls the handler
my SetLablelIndes(listOfFolders)
--
on SetLablelIndes(folderList)
--handler declaration
repeat with thisFolder in folderList
tell application "Finder"
set the label index of thisFolder to 2
end tell
end repeat
------------
------------------
--Top Level
set labelNumber to 3
set listOfFolders to choose folder with prompt "Pick folders to work with" with multiple selections allowed
tell application "Finder" to reveal item 1 of listOfFolders
--this line calls the handler
set countOfFolders to my SetLablelIndes(listOfFolders, labelNumber)
display alert "This script set the labels on " & (countOfFolders as text) & " items to " & (labelNumber as text)
--
on SetLablelIndes(folderList, numberForLabel)
--handler declaration
set x to 0
repeat with thisFolder in folderList
tell application "Finder"
try
set the label index of thisFolder to numberForLabel
set x to x + 1
end try
end tell
end repeat
end SetLablelIndes
------------
_______________________________________________
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/archives/applescript-users
This email sent to email@hidden