set on_day to Read_Plist("day")
set state of button "day" in window "main" to on_day
Now I know that its getting the right value from the .plist as I can throw in a return call right there and it shows that it is indeed picking up a 0. If I change the on_day to “0” it still fails. I double and tripple checked the IB connections, and all is well…
Error I am getting is: NSReceiverEvaluationScriptError: 4(1)
I tried to search around and see what this could be, and I saw mention of setting check boxes not working in “awake from nib”'s, but never why, so could this have something to do with it?
try
set theList to paragraphs of (read ("/files.txt" as POSIX file))
if (theList > 0) then
repeat with tempFile in theList
addToTable((tempFile) as string)
end repeat
end if
end try
In this gem, I am trying to read the file and get each line to come up as an object in the list and then add each item to a table I have…
With that one, I get: "Can’t make {“test”, “”} into type number, date, or text (-1700)
So if anyone could help with either, and, in the process, stop me from jumping off a bridge, we can be best friends, k?
Still fails with the (on_day as number)…same errror
Heres the addToTable code…
on addToTable(theFile)
set theDataSource to data source of table view "files" of scroll view "files" of window "main"
set update views of theDataSource to false
(* Add a data row and it's contents *)
tell theDataSource
set theRow to make new data row at the end of the data rows
set contents of data cell "files" of theRow to theFile
end tell
(* Display the new contents *)
set update views of theDataSource to true
end addToTable
on clicked theObject
set theDataSource to data source of table view “files” of scroll view “files” of window “main”
make new data column at end of data columns of theDataSource with properties {name:“col1”}
try
set m to (open for access file (“Macintosh HD:files.txt” as string))
set theList to paragraphs of (read m)
if theList ≠{} then
repeat with tempFile in theList
my addToTable(tempFile)
end repeat
end if
end try
end clicked
on addToTable(theFile)
set update views of theDataSource to false
set theRow to make new data row at the end of the data rows of theDataSource
set content of data cell “col1” of theRow to theFile
set update views of theDataSource to true
end addToTable
I used a button as my tigger but you should be able to adapt to your own situation.
hope this helps. it worked on my system.
Sorry forgot to add in IB you must drag an instance of “ASKDataSource” from the applescript palette into your nib and cntrl-drag from your tableview to it connecting as a datasource in the table view outlets.
I think you’re referencing the item using the wrong syntax. You’ve got an “in” rather than an “of” when referencing the window of the button. In 10.4 this seems to work, but I don’t remember this syntax being valid in earlier versions. Maybe “in” was always OK and I just never realized it? What OS/Xcode version are you under? Try this instead…
set state of button "day" of window "main" to on_day
Other than this, I see nothing wrong with your code. My test project worked fine and set it’s state using the line above. You must be either getting an incorrect value class for the on_day variable, your objects are not named as you think they are, or a connection is not made correctly.
What is your awake from nib handler attached to? If it’s attached to the button, or it’s super view (like it’s window)
then no, it shouldn’t matter. If it’s attached to an object that “awaken’s” long before the button does, technically the button doesn’t exist yet so referencing it is not cool.
hi again
I agree with Jobu
the coding is trivial and no more than the basic switch illustrated below
if (state of button “day” of window “main” = 1 and on_day = 0) then
set state of button “day” of window “main” to 0
end if
if (state of button “day” of window “main” = 0 and on_day = 0) set state of button “day” of window “main” to 0
end if
if (state of button “day” of window “main” = 0 and on_day =1) set state of button “day” of window “main” to 1
end if
if (state of button “day” of window “main” = 1 and on_day =1) set state of button “day” of window “main” to 1
end if
Questions: Are you always setting on_day to 0? Are you testing the button state before setting it to on_day?
Add these to Jobu’s observations and the answer (must) be in there!
Its running on the “awake from nib” of the window. Also, changing it to “of window” didn’t help, still getting the same error. I can tell from having a return statement in there that its getting right to that point and that the setting of the checkbox is the place of the error.
Riverman: even just setting it to
set state of button "day" of window "main" to 0
(hence ignoring all if logic) does not work.
Model: Powerbook G4 1.33 Ghz
AppleScript: Xcode 2.1
Browser: Safari 412.5
Operating System: Mac OS X (10.4)
Just on a whim I moved the project over to my other mac, and it works…I am going to wipe this machine today (Its been giving me a lot of trouble) and see if that changes anything.
On more quick question…is there any reaosn that I couldnt have
set m to (open for access file ("Macintosh HD:files.txt" as string))
set fileNames to paragraphs of (read m)
if fileNames ≠{} then
repeat with tempFile in fileNames
my addToTable(tempFile)
end repeat
end if
in a try? Everytime I do it, it dosent seem to work, but if I take out the try, it works great
1)check boxes work fine on “wake from NIB”!
2)If you look back at the code solution I sent the section of code discussed is inside a try statement!
Without the full code and the context of the events there is not much more I can suggest.
PS
It is very rarely the machine at fault. Remember you are writing code not running an app and look for the error in there. I have never wiped my system since installing OSX v1. OSX is robust beyond compare!! (ok famous last words but no lie)
Agreed, after moving the code it works fine. I agree with you about the robustness of OS X (Have been a BSD guy for years before this), but this machine has been through some crazy stuff (beta OS’s, half way installs, etc) and has been having some very crazy other symptoms. I have been putting off reformatting it with 10.4.
Sorry about that, for some reason I had a problem with it, but it ended up being my own stupidity.
I do have one more question, is there an easy/accepted way to remove line breaks from a file when reading it? The files.txt often has some line breaks towards to bottom that I would like removed when adding to the table. I tried a if statements checking for ASCII charecter 10 and 13 as well as trying to find " ", but none seemed to remove them.
Thanks again riverman, sorry for the confusion on 2, didn’t mean to make anyone mad
I would do that by running the original data file through either a grep or perl script using a do shell command at the start on the main script.
riverman