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"
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
Browser: Safari 525.13
Operating System: Mac OS X (10.4)
neither of your scripts work!
yours gets “Apple Event Failed” (tried in many ways)
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
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
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 !
i had a look through the examples and took some guesses, but got nothing.
any chance of some quick example code??
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
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"
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).
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
Great to see. You’re welcome