I set up a table bound to an array controller.
I’m running the below to grab the user names from the computer and put them into the table…
The issue I’m having with this is that I’m ending up with in the bottom row every time I load the values in.
on checkforusers_(sender)
set compusers to do shell script "/usr/bin/dscl . list /Users | grep -v eccsadmin | grep -v ^_ | grep -v root | grep -v uucp | grep -v amavisd | grep -v nobody | grep -v messagebus | grep -v daemon | grep -v www | grep -v Guest | grep -v xgrid | grep -v windowserver | grep -v unknown | grep -v unknown | grep -v tokend | grep -v sshd | grep -v securityagent | grep -v mailman | grep -v mysql | grep -v postfix | grep -v qtss | grep -v jabber | grep -v cyrusimap | grep -v clamav | grep -v appserver | grep -v appowner"
display dialog compusers
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
repeat with i from 1 to count of paragraphs of compusers
set oneRecord to paragraph i of compusers
set my theData to {{theUsername:text item 1 of oneRecord}} & my theData
end repeat
set AppleScript's text item delimiters to oldDelims
end checkforusers_
In addition to this I’m unsure how to access these values from the array controller. Such that I can click on a value…then click a button to act on those values.
All those greps – you can use a single grep as in “grep -v root|uucp|amavisd|…”. And your text item delimiters don’t seem to be involved in anything, but maybe you cut that code out.
You’re probably getting because you have an empty paragraph at the end. Try adding something like ‘if oneRecord is not “”’ before the “set myData…” line.
As for getting the selection, it depends on how you have bound myData to the Table. Have you used an NSArrayController?
I do have an empty paragraph at the end however the line you suggested does not remove it from the end.
I added "grep -v “^$” to the grep lines to remove any blank lines from the returned information.
Sorry for the newbi-ness of this post.
I followed the “florida” sample application which is on here somewhere.
I created an array controller in the IB and then bound both columns for the table to the array. theUsername and the UID are the two columns. The “value” of both columns are bound to the array controller.
the Class is reported as NSMutableDictionary in IB.
repeat with i from 1 to (count of paragraphs of compusers)-1
The easiest way to get information about the selection is to ask the NSArrayController. So you’ll need to add a property and make it an outlet of the array controller – let’s assume you call it arrayController. To find the selection, you can call its selectedObjects method, which returns a list of the selected items:
set selectedItems to arrayController's selectedObjects() as list
on showuser_(sender)
set selectedItems to myuserarray's selectedObjects() as list
display dialog selectedItems
end showuser_
I’ve read a bunch of tutorials but I’m unclear what to do with the list at this point to access the “string” information hidden in the list that is returned…the above returns a dialog with a long string of chinese characters…weird
set selectedItems to myuserarray's selectedObjects() as list
set theItem to item 1 of selectedItems as string
display dialog theItem
but I get in the console
2/19/10 8:30:57 AM Migration[599] *** -[MigrationAppDelegate showuser:]: Can’t make some data into the expected type. (error -1700)
then I tried:
set selectedItems to myuserarray's selectedObjects() as list
set theItem to theUsername of selectedItems as string
display dialog theItem
then get
2/19/10 8:40:32 AM Migration[653] *** -[MigrationAppDelegate showuser:]: Can’t make theUsername of {{theUsername:“mdhredhead”}} into type string. (error -1700)