• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling AppleScript from a Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling AppleScript from a Cocoa app


  • Subject: Re: Calling AppleScript from a Cocoa app
  • From: Phil <email@hidden>
  • Date: Tue, 6 Sep 2005 11:43:07 -0400

Thanks... I did see that and am using initWithContentsOfURL as suggested. In fact, in order to solve this, I've scaled back my efforts to the point where I'm simply modifying the sample project from the .dmg to ensure as much as possible that my code is not introducing any new problems. The modifications are as follows:

Modify the script.scpt to include a second function:

on show_message(theMessage)
    tell application "iTunes"
        display dialog theMessage
    end tell

    return 0
end show_message

on OGNewObj(objName)
tell application "OmniGraffle Professional 3"
activate
set myDocument to front document
tell first page of myDocument
-- set theShape to make new shape at front of graphics with properties {origin:{20, 20}, size:{192, 64}, name:"rectangle", text:"My shape"}
-- set theShape to make new shape at front of graphics with properties {origin:{20, 20}, size:{192, 64}, name:"rectangle", text:"My shape"}
set theShape to make new shape at front of graphics with properties {origin:{20, 20}, size:{100, 60}, name:objName, text:objName}
end tell
end tell
return 0
end OGNewObj


Next, modify AppController.m to add a call to the second function by inserting a definition for the new function at line 23:
#define kHandlerName2 (@"OGNewObj")


And then inserting the code to call it at line 49 (which is simply a copied block from the example with variables renamed):

// Begin added code
NSDictionary *errorInfo2 = nil;
errorInfo2 = nil;
/* Call the handler using the method in our special category */
NSAppleEventDescriptor *result2 = [script callHandler: kHandlerName2 withArguments: arguments errorInfo: &errorInfo2];


    int scriptResult2 = [result2 int32Value];

/* Check for errors in running the handler */
if (errorInfo2) {
[self handleScriptError: errorInfo2];
}
/* Check the handler's return value */
else if (scriptResult2 != noScriptErr) {
NSRunAlertPanel(NSLocalizedString(@"Script Failure", @"Title on script failure window."), [NSString stringWithFormat: @"%@ %d", NSLocalizedString(@"The script failed:", @"Message on script failure window."), scriptResult2], NSLocalizedString(@"OK", @""), nil, nil);
}
// End added code


What is throwing me is that that the first function (show_message) works while the second (OGNewObj) does not. I've confirmed that both functions do what's expected by running the script stand-alone after adding the following to script.scpt:

on run
    show_message("This is only a test")
    OGNewObj("This is only a test")
end run

Any ideas?

Thanks,
Phil

On Sep 6, 2005, at 4:45 AM, email@hidden wrote:

Hi,

have you paid attention to the following remark in the code:

/* Here I am using "initWithContentsOfURL:" to load a pre-compiled script, rather than using "initWithSource:" to load a text file with AppleScript source.
The main reason for this is that the latter technique seems to give rise to inexplicable -1708 (errAEEventNotHandled) errors on Jaguar. */


GV


Am 06.09.2005 um 10:22 schrieb Phil:


Thanks... that was the link that I attempted to include in my message which apparently didn't work ;-)

On Sep 6, 2005, at 4:11 AM, email@hidden wrote:






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


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Calling AppleScript from a Cocoa app (From: Phil <email@hidden>)
 >Re: Calling AppleScript from a Cocoa app (From: "email@hidden" <email@hidden>)
 >Re: Calling AppleScript from a Cocoa app (From: Phil <email@hidden>)
 >Re: Calling AppleScript from a Cocoa app (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: Calling AppleScript from a Cocoa app
  • Next by Date: Re: Calling AppleScript from a Cocoa app
  • Previous by thread: Re: Drag to Nowhere and Disappearing Smoke
  • Next by thread: Re: Calling AppleScript from a Cocoa app
  • Index(es):
    • Date
    • Thread