AppDelegate ComboBoxClick: Can’t make script into type text err -1700

Hi folks,

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)

Thank you in advance.

It could be because you’ve used objectValueOfSelectedItem instead of objectValueOfSelectedItem(). But I’m not sure why you’re not using stringValue() instead.

Thank you a lot for your suggestion.

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.

Mariano R.

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») 

Hi Shane,

I’ve just try out your last snippet but still throws the
– Can’t make «script» into type text. (error -1700) – error message

Anyway, this other solution instead seems to be a valid into my Xcode project:

set all_answers_list to every paragraph of (do shell script “cat ~/Desktop/all_answers.txt”)

I much appreciate your help.

On the other hand, any suggestion about a good book to learn AppleScriptObjc?

Marius

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())

The only one I know of is mine:

https://www.macosxautomation.com/applescript/apps/

Your code works fine, I’ve just needed to add ‘Desktop’ to the url, like this:

set srcFile to (path to desktop as text) & “:desktop:all_answers.txt”

Thank you for your great work on this subject.

I definitely look into your book.

I think that AppleScript is the best for some specific scenarios and combining it with Object C, make it much more powerful.

That’s going to include Desktop twice, not something one would normally want…

I know but for some obscure reason at my work desktop does not work unless I include ‘Desktop’ in the path.

At my home desktop there is no need to include it ???