Thursday, May 28, 2020

#1 2020-02-18 12:25:42 pm

Marius_Magnificus
Member
Registered: 2019-05-05
Posts: 16

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.

Offline

 

#2 2020-02-18 04:38:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

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

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2020-02-18 10:12:31 pm

Marius_Magnificus
Member
Registered: 2019-05-05
Posts: 16

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

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.

Offline

 

#4 2020-02-18 10:20:43 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

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

Marius_Magnificus wrote:

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 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:

Applescript:

set srcFile to srcFile as «class furl»
set lns to paragraphs of (read file srcFile as «class utf8»)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2020-02-19 10:47:25 am

Marius_Magnificus
Member
Registered: 2019-05-05
Posts: 16

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

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

Offline

 

#6 2020-02-19 04:50:38 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

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

Marius_Magnificus wrote:

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



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:

Applescript:

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

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



It's very much going the long way round. You could always do it in ASObjC:

Applescript:

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

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



The only one I know of is mine:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2020-02-20 08:57:22 am

Marius_Magnificus
Member
Registered: 2019-05-05
Posts: 16

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

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.

Offline

 

#8 2020-02-20 04:48:51 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6369

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

Marius_Magnificus wrote:

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"



That's going to include Desktop twice, not something one would normally want...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2020-02-21 04:57:05 pm

Marius_Magnificus
Member
Registered: 2019-05-05
Posts: 16

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

Shane Stanley wrote:
Marius_Magnificus wrote:

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"



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 ???

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)