Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Creating Cocoa objects within Applescript possible?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating Cocoa objects within Applescript possible?



Thanks Hank

I tried your suggestions, which eliminated the original compile error, but now I'm getting a new error:

Can’t set URL to «event appScalM» "URLWithString:" given «class of C»:"NSURL", «class witQ»:scriptUrl. Access not allowed. (-10003)

Here's the modified script

property scriptUrl : "http://localhost/PageManager/PMXPage.php";
property invocation : ""

on clicked theObject
if the name of theObject is "doSearch" then
if (invocation = "") then
set url to call method "URLWithString:" of class "NSURL" with parameter scriptUrl
--set invocation to call method "invocationWithURL:" with parameter url
end if

--set x to call method "invokeWithSelector:arguments:" of invocation with parameters {"get_page_record", 4903}
--display dialog page_number of x as string
end if
end clicked


The weird thing is, I wrote a Cocoa controller class that wraps up all that stuff into a single method call and that works but it doesn't seem to work when the return type isn't a "normal" AppleScript type like string (NSString) , array (NSArray), record (NSDicrtionary). I even tried to add a method to my Cocoa controller that encapsulates the calls to NSURL and PHPInvocation but those fail with the same compile errors.

Here's the Cocoa controller

@implementation NSApplication (PHPController)

// This one compiles and works
- (id) invokeScript:(NSString *) inURL
withSelector:(NSString *) inSelector
arguments:(id) inArgs
{
NSURL *url = [NSURL URLWithString: inURL];
PHPInvocation *invocation = [PHPInvocation invocationWithURL: url];
id result = [invocation invokeWithSelector: inSelector arguments: inArgs];

return result;
}


// These both fail with the above compile error
- (id) urlWithString:(NSString *) inString
{
	return [NSURL URLWithString: inString];
}

- (id) invocationWithURL:(NSURL *) inURL
{
	return [PHPInvocation invocationWithURL: inURL];
}

@end

Do you know if return types from any called method must be one of the basic types like NSString, NSArray, NSDictionary etc...?


On Nov 10, 2008, at 7:34 AM, HAMSoft Admin wrote:

I haven't tested this, but the first line should look like this... notice you missed the ":" and then the variable you input is done with "with parameter"...

set url to call method "URLWithString:" of class "NSURL" with parameter "http://localhost/Test/TestPHPScript.php";

The other call method lines have the same problem. The colon is part of the method name so you need those. The colon tells the method that there is a parameter needed. Methods without a colon have no parameter. Methods with multiple parameters, such as NSFont's "fontWithName:size:" have 2 colon's. These require you put the parameters in with the wording "with parameters" as opposed to "with parameter". And when you use "with parameters" you have to put the variables in as a list. This method would look like the following...

set myNSFont to call method "fontWithName:size:" of class "NSFont" with parameters {"Helvetica", 12.0}

I hope that helps!

Sincerely,
Hank McShane
http://www.hamsoftengineering.com

<hamsoft-logo.png>




On Nov 9, 2008, at 5:30 PM, Ken Tozier wrote:

Hi

I wrote a Cocoa class that enable the easy query of PHP scripts but am finding that when I switch over to AppleScript, I can't figure out how to initialize it.

In Cocoa it is initialized like this

NSURL *url = [NSURL URLWithString: @"http://path/to/php/script.php";];
PHPInvcation *invocation = [PHPInvcation invocationWIthURL: url];

I tried to do something similar in AppleScript but am stuck on how to create Cocoa objects from within it. Here's what I tried so far:

property invocation : ""

on clicked theObject
if the name of theObject is "doSearch" then
if (invocation = "") then
set url to call method "URLWithString" of class "NSURL" with "http://localhost/Test/TestPHPScript.php "
--set invocation to call method "invocationWithURL" of class "PHPInvocation" with url
end if
--set x to get_page_record
call method "uppercaseString" of (contents of text field "inputField" of window "myWindow")
end if
end clicked


When I go to build the project however, I'm getting the following compile error

Expected “into”, variable name, class name, other parameter name or property but found “"”. (-2741)

Is it even possible to create new Cocoa objects within AppleScript and if so, how does one go about doing it?

Thanks for any help



_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Studio mailing list (email@hidden )
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Studio mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Creating Cocoa objects within Applescript possible? (From: Ken Tozier <email@hidden>)
 >Re: Creating Cocoa objects within Applescript possible? (From: HAMSoft Admin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.