Get contents of tables by row

Hi,
In my script a variable gets set the selected row, but is only a number. How do i get the contents of that cell?


		set _sApp to selected row of table view "app_list" of scroll view "al" of window "main"
		set sApp to contents of _sApp
		display dialog sApp

my table looks like this
|------------------------------|

– title -------- title –
– cell -------- cell –
------------------------------
– THIS ------ cell –
------------------------------

and i want the text in ‘THIS’

thanks in advance

Have you looked in the AppleScript dictionary for the properties of table view? In addition to “selected row” (and many others), it shows another property:

selected data row (data row) : the data row that is selected

and clicking the hyperlinked “(data row)” class gives you its definition, including the property:

contents (any) : the contents of the data row

Putting that together, it means you can:

get contents of selected data row of table view "app_list" in scroll view "al" in window "main"

Tom
BareFeet
http://www.tandb.com.au/applescript/

Hi,

try this

set theTableView to table view "app_list" of scroll view "al" of window "main"
set selectedDataRow to selected data row of theTableView
set theContent to contents of data cell "Title1" of selectedDataRow of theDataSource
-- "Title1" is the name of the column 
display dialog theContent

Heiner

Browser: Safari 525.13
Operating System: Mac OS X (10.4)

:frowning: neither of your scripts work!
@Barefeet
yours gets “Apple Event Failed” (tried in many ways)
@Heiner
set theContent to contents of data cell “Title1” of selectedDataRow of theDataSource <-<- where did you get this var from?!?
tried with many thing and got messy errors

maybe i am explaining myself wrong - here is an image of my table
http://file.nuttysoftware.com/as_img.png

and i want to get whatever is stored in the cell where “iTunes Helper” is (i mean the cell with the application name of the selected row)

thanks if you can help :slight_smile:

Hi,

theDataSource is the name of the data source you have to attache to the table view (normally in the awake from nib - handler). See: Developer → Examples → AppleScriptStudio → Table Sort and Table !

Heiner

:confused: i had a look through the examples and took some guesses, but got nothing.
any chance of some quick example code??
thx

Hi,

The example codes are simple and instructiv. Examine the examples exactly, especially ‘Table’; look into the Interface Builder’s MainMenu.nib; there are two examples ‘witout’ and ‘with’ data source; if you take the last one, you have to add a data source to the project (drag from palette ‘AppleScript’ the data source (a blue cube) to the nib-pane and connect it with the table view by ctrl-drag from the table view to the cube, connect it in the inspector pane).

Maybe this will help you

Heiner

It works here, for me. Maybe your specification of the table doesn’t match your project. Try runing your program, select a row in your table, and run this script in Script Editor:

tell application "My Application Name" -- change this to the name of you program
	set theObject to first responder of front window
	get contents of selected data row of theObject
	--get contents of selected data row of table view "app_list" in scroll view "al" in window "main"
end tell

If that works, try uncommenting the last line. If the last line doesn’t work, then it seems that you’re not correctly referring to your table. Maybe the name is wrong or it’s in another view (eg tab view).

Tom
BareFeet

that worked perfectly!
I uncommented the line and it still worked so im not sure what the problem was, im gonna put it into my app and see if it works
thanks! :smiley:

Great to see. You’re welcome :slight_smile: