Calling Foundation Functions?

Anyone figure out how to call Foundation functions like NSMakeSize()?

Hi Craig,

Thanks, your tutorial was great! I am now trying to incorporate some of my old Call methods into the new format, namely getting date strings. Just some of the common foundation calls…

set thecur to (current date)
set myDatestring to call method “descriptionWithCalendarFormat:timeZone:locale:” of object thecur with parameter “%B %e” as string

This call is actually deprecated in 10.6 now but I can’t seem to get it into the right format with the underscores and multiple colons in the method etc.

Do we have to use a separate script object with Property parent: class “NSDate” ?

Rob

PS My other quest( on another thread) is to see how to populate a table. I am assuming “append theDataSource with theData is not the way to go”

Model: MacBook Pro 2.4 GHz
Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Hi Rob,

Q1 is below. I think there is much work being done by the AppleScriptObjC development team. Things are just not working the way they should. :slight_smile:

Q2 - Inserting data in table views. That is the subject of my next tutorial. I will try to have it up today.

This should work but it doesn’t.


property NSDate : class "NSDate"
set formatedDate to NSDate's |date|()'s descriptionWithCalendarFormat_timeZone_locale_("%B %e", null, null)
log formatedDate

I created an Objective-C class called “NewDate” and it works fine.


--put this above your script declaration
property NewDate : class "NewDate" of current application

--call it with this
set theDate to NewDate's formatDateWithFormat_("%B %e")

Objective-C Code

Thanks Craig,

That is very helpful, especially to know things don’t work exactly as expected. Will see you tutorial later. Can’t wait.

Rob

Hi again Craig,

I just got around to trying out the homemade date class (busy setting up tableView) but it doesn’t seem to work yet. I put the call in the setTextViewFromTextField_ handler and various other places too. I alos tried the original NSDate method with no luck, like you.



property NewDate : class "NewDate" of current application

script PartOneAppDelegate

	property parent : class "NSObject"
	
	property textView : missing value
	property textField : missing value
	property aWindow : missing value
	
	on setTextViewFromTextField_(sender)
		set theDate to  NewDate's formatDateWithFormat_("%B %e")
		set textFieldValue to textField's stringValue()
		
		textView's setString_(formatedDate)
		
	end setTextViewFromTextField_

etc....


I wonder if there are other foundation classes that won’t simply work with there own class names ( NSdate etc.)
Is this a bug?

Thanks, Rob

Hi Rob,

You are setting “theDate” to the formatted date but you are setting the textView to “formatedDate.”
Correct that and it should work.

When something like this is not working, a log statement will help you narrow down where the error is.

eg.


set theDate to NewDate's formatDateWithFormat_("%B %e")
log theDate

hth,
Craig

Hi Craig,

Sorry about the typo. I actually had the correct variable in there and it really doesn’t work. This is what I do have now and nothing happens. It does work when I have the original method set the textView to the textField contents so I know it’s hooked up right.

Rob



property NewDate : class "NewDate" of current application

script PartOneAppDelegate
	
	property parent : class "NSObject"
	
	
	property textView : missing value
	property textField : missing value
	property aWindow : missing value

	on setTextViewFromTextField_(sender)
		set theDate to my NewDate's formatDateWithFormat_("%B %e")
		textView's setString_(theDate)
	end setTextViewFromTextField_

etc...


I am really curious about this. Would you mind emailing me a zipped up copy?
craigw@macscripter.net

Ok, thanks for the email. Now that I see your code, I see the Objective-C class is missing.
Once you add it everything will work. :slight_smile:

Hi Craig,

Somehow I added a “my” before the

NewDate’s formatDateWithFormat_(“%B %e”)

I removed it and it works fine now.

After reading your samples and now Matt Neuberg’s (he just posted) I am getting the feeling one really does need to have a firm grasp of OBJ-C to know what is going on with this ASOC bridge. Sure, you can learn enough to connect the interface and do some simple applescript but beyond that, it will get really confusing. I have no experience writing in OBJ-C but have read Stephen Kochan’s excellent book and even added some code to class files in my ASS projects. But I am a long way from really understanding things. But in time I may be able to convert my projects as I see enough examples. Still hopeful!

Thanks for your help,

Rob

Did anyone figure out how to call NSMakeSize() as in Craig’s original?

You don’t. Instead, you pass a record like this:

		theWindow's setContentSize_({|width|:theWidth, height:theHeight})