Wednesday, December 13, 2017

#1 2009-10-16 12:56:10 am

Whiterock
Member
Registered: 2009-09-09
Posts: 30

String Constant to NSString Object

I can get a string generated by an internal method into an NSString object easily enough and use the NSString object easily:

Applescript:


tell class "NSString" of current application
set theString to stringWithString_(my get_f_as_alias(thePath) as text)
end tell
set theList to theString's componentsSeparatedByString_(":")

I've tried everything I can think of to get a string constant into an NSString object but without success. e.g.:

Applescript:


tell class "NSString" of current application
set aString to initWithString_(PathList as text)
end tell

I get an error message on the console:
+[NSString initWithString:]: unrecognized selector sent to class 0x7fff70791258

Offline

 

#2 2009-10-16 01:46:09 am

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

Re: String Constant to NSString Object

Just use stringWithString_ again.


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

Offline

 

#3 2009-10-16 01:35:15 pm

Whiterock
Member
Registered: 2009-09-09
Posts: 30

Re: String Constant to NSString Object

It must seem odd but stringWithString_ was the first method I tried. It worked in the first example I sent in the posting but didn't work in the latter. Now it does?!

I'm stuck in the next step of my process – appending some text to the NSString object. I tried

Applescript:


       tell class "NSString" of current application
           set aString to stringWithString_(":Volumes:")
       end tell
       set aString to my aString's stringByAppendingString_(a reference to anString)

that was a disaster. I tried using the NSMutableString's appendString_ to no avail:

Applescript:


       tell class "NSMutableString" of current application
           set aString to stringWithString_(":Volumes:")
       end tell
       my aString's appendString_("Twaddle:")

aString was unchanged after this last step. Any ideas?

Offline

 

#4 2009-10-16 03:47:41 pm

Craig Williams
Administrator
From:: Ft. Smith, AR
Registered: 2006-12-07
Posts: 888

Re: String Constant to NSString Object

Change this:

Applescript:

my aString's appendString_("Twaddle:")

to this:

Applescript:

aString's appendString_("Twaddle:")

If you look in the console it will tell you that "aString" is not key-value coding compliant.
This is because you do not have "aString" setup as a property but a local variable.

Offline

 

#5 2009-10-16 03:58:32 pm

Whiterock
Member
Registered: 2009-09-09
Posts: 30

Re: String Constant to NSString Object

Thanks Craig. I couldn't decode that piece of jargon in the console. Now I know.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)