This is my first Applescript Studio project and I’m having a few beginner issues…
I’m a technician who fixes Macs and I’m seeing the need for a program that will display a list of apps installed on the machine, allow me to check off several of them, then begin opening and quitting them one after the other. Repeating endlessly or until so many repetitions have occured. Here is what I have so far:
on awake from nib theObject
global myData
global myList
tell application "Finder"
set myData to the name of application files in the entire contents of folder "Applications" of startup disk
end tell
set myList to every item of myData
set theDataSource to make new data source at end of data sources with properties {name:"Applications"}
tell theDataSource
make new data column at end of data columns of theDataSource with properties {name:"application", sort order:ascending}
set sort column of theDataSource to data column "application" of theDataSource
end tell
set data source of theObject to theDataSource
append theDataSource with myList
make new data column at end of data columns of theDataSource with properties {name:"test"}
end awake from nib
What this has done is pull up the list of apps and populate it into a table with a column of checkboxes to the left of each app. So far so good. Here’s where I’m stuck…
The list appears to be sorting by directory. In other words, Apps located inside the Application directory are sorted A-Z, then below is all the Apps found in the Adobe Acrobat folder from A-Z, etc.
When I check a checkbox, the app name next to it changes to a 1, when I uncheck it, it changes to a 0. Obviously both undesirable.
The list is too thorough. I’d like it to only pull up “.app” files and it’s including “.exe” as well
If someone could help me overcome these things, I might be able to get the rest on my own. I’m just having such a problem locating good info about checkboxes.
Hi slemson - it’s been a long time now so I hope my answer is not relevant anymore.
First you need to create a new column for the checkbox. Then in the IB you need to associate the clicked handler to your script.
In the handler, don’t try to treat the checkbox as regular buttons. The state of the checkboxes are really "contents of data cell … ". Oddly enough when I check a checkbox, the content (after coerced into a string) is empty, but when unchecked it’s “true”.
Ok now I’m running into another puzzle: I’d like to disable/enable some of the checkboxes in the table column, but I can’t figure out how to get to the button cell object inside the data cell - it’s not one of the property of a data cell…
I’m pretty sure you can’t do it on a row by row basis. I believe that when you add a custom object to a table (such as the checkbox or a popup, etc.), it adds that object formatter to the header cell of the column. When the table has multiple rows, the rows in that column are just representations of the formatter of header cell and you cannot modify them on a row by row basis, only on the formatter in the header cell whcih will effect the entire column. So, modifying the enabled property of the header cell of a column that has been formatted with a checkbox is possible:
but doing it to a specific row is not. I hope someone contradicts me on this (or at least finds a workaround) but I fear not.
Right, in the project I posted above, it is quite clear that you can set the contents of individual cells to true or false and the checkbox formatter then displays this as either a checked or unchecked box. Enabling or disabling the checkbox itself would appear to be impossible but modifying the enabled property of the header cell which effects the formatter of all cells in that column will work, just not on individual cells.
i didn’t think you folks would be missing something so simple.
i agree with jon8 that this isn’t going to be possible without major workarounds.
properties like enabled of table cells are determined by the header cell.
as i mentioned on another thread in the past day, i did notice a workaround on the AS Studio mailing list for directly messing with properties of individual table cells. there are caveats, but i don’t know how impractical it really is actual use.
It works. You can mess with individual table cell elements.
you should be able to use this to enable/disable individual checkboxes.
however, it’s slow. I tried it with a 4x5 table, and the table display hitches for a second or two. The real problem comes when the user tries to resize the window, the hitch is unpleasant there.
If you have a project with non-resizable windows, and a table with few cells, this might work just fine, tho.
i wish it would work for my current project.
Attach a “will display cell” handler to the table view in IB, and try this code:
on will display cell theObject table column tableColumn cell theCell row theRow
if ((content of theCell as string) is "Error") then
set text color of theCell to {30000, 0, 0}
else
set text color of theCell to {0, 0, 0}
end if
end will display cell
While this may work for text attributes of a cell, I don’t see any way of making the cells enabled/disabled which is the problem I thought we were trying to tackle.