I have a combo box (NSComboBox : NSTextField) filled out of string elements and I’ve created the following handler to deal with it:
on comboBoxClick_(sender)
set title to comboBox’s objectValueOfSelectedItem as string
my find_the_selected_title(title)
end ComboBoxClick_
For some reason I receive the following err. message:
-[AppDelegate comboBoxClick:]: Can’t make «script» into type text. (error -1700)
I’ve no idea what’s going on because I’m passing a string to another handler and I’m not able to find any solution (I even tried to return true as final statement, wrap the handle call into a try an error block, but neither of them work)
It could be because you’ve used objectValueOfSelectedItem instead of objectValueOfSelectedItem(). But I’m not sure why you’re not using stringValue() instead.
Actually I’ve just identified the origin of the issue and it has nothing to do with the combo box handler.
It was the find_the_selected_title handler, and to be more specific, the problem was with the following statements:
set the_alias to alias “Macintosh HD:Users:Marius:Desktop”
set srcFile to (the_alias as text) & “all_answers.txt”
set lns to paragraphs of (read file srcFile as «class utf8»)
The above code works in Applescript but not in Xcode AppleScriptObjC
I was able to fixed it with the following code:
set all_answers_list to every paragraph of (do shell script “cat ~/Desktop/all_answers.txt”)
By the way, using ‘stringValue()’ instead of ‘objectValueOfSelectedItem()’ is much better, thank you for that as well.
I suspect the issue is either the missing colon (which you might have had in the actual code), or the use of file as a specifier. Better to do something like this:
set srcFile to srcFile as «class furl»
set lns to paragraphs of (read file srcFile as «class utf8»)
You have a missing colon in your path. I also forgot to remove the file that’s no longer needed, and your alias specifier has the same problem as file. Better to use something like this:
set srcFile to (path to desktop as text) & "all_answers.txt"
set srcFile to srcFile as «class furl»
set lns to paragraphs of (read srcFile as «class utf8»)
It’s very much going the long way round. You could always do it in ASObjC:
set srcFile to (path to desktop as text) & "all_answers.txt"
set {theText, theError} to current application's NSString's stringWithContentsOfFile:(POSIX path of srcFile) encoding:(current application's NSUTF8StringEncoding) |error|:(reference)
if theText is missing value then error theError's localizedDescription() as text
set lns to theText's componentsSeparatedByCharactersInSet:(current application's NSCharacterSet's newlineCharacterSet())