Re: Getting the row number of an item in a list
Re: Getting the row number of an item in a list
- Subject: Re: Getting the row number of an item in a list
- From: Christopher Nebel <email@hidden>
- Date: Thu, 9 Oct 2008 11:52:00 -0700
On Oct 8, 2008, at 7:23 PM, Michelle Steiner wrote: On Oct 8, 2008, at 6:52 PM, Peter Baxter wrote: tell application "Printer Setup Utility" set myList to name of every printer tell application "System Events" choose from list myList end tell set newPrinter to --the number of the relevant printer in my list. If I choose the 5th printer in the list, I get 5. end tell
tell application "Printer Setup Utility" set myList to name of every printer tell application "System Events" choose from list myList end tell set theSelection to item 1 of the result end tell repeat with i from 1 to count of myList if item i of myList is theSelection then set newPrinter to i exit repeat end if end repeat
This certainly works (there are variants, but they boil down to the same thing), but realize that it's often not necessary. For instance, if you wanted to set the current printer to the one selected from the list, the printer name would be sufficient, and actually superior to the index:
tell application "Printer Setup Utility" set myList to name of every printer tell me choose from list myList end tell set newPrinterName to item 1 of the result set current printer to printer newPrinterName end tell
--Chris Nebel AppleScript Engineering |
_______________________________________________
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