Experimental Physics and
| |||||||||||||||
|
To include an Objective-C source file in an application just add it to the source list in the application Makefile: example_SRCS += exampleObjC.m To link the Foundation framework into an application add the following as well: example_LDFLAGS += -framework Foundation Here's a short example showing how the Foundation framework can be used to send AppleScript messages to other applications: /* * exampleAppleScriptRecord.m * * Simple Objective-C/AppleScript subroutine record * * To use this record in an application: * * 1) Make the following changes to the application Makefile: * - Add exampleAppleScriptRecord.m to the application SRCS. * - Add -framework Foundation to the application LDFLAGS. * 2) Add the following line to the application database description: * function(exampleAppleScriptProcess) * 3) Add a record to the application database: * record(sub,"setVolume") * { * field(SNAM,"exampleAppleScriptProcess") * } */ #import <Foundation/Foundation.h> #include <subRecord.h> #include <alarm.h> #include <errlog.h> #include <recGbl.h> /* * Shim between EPICS and NSAppleScript class. */ long exampleAppleScriptProcess(struct subRecord *psub) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSDictionary *err; NSAppleScript *nsa; nsa = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat: @"tell application \"Finder\" to set volume %g\n", psub->A]]; if ([nsa executeAndReturnError:&err] == nil) { errlogPrintf("Failed to run AppleScript: %s\n", [[err objectForKey:NSAppleScriptErrorMessage] cString]); recGblSetSevr(psub, SOFT_ALARM, INVALID_ALARM); } [nsa release]; [pool release]; return 0; } -- Eric Norum [email protected] Advanced Photon Source Phone: (630) 252-2793 Argonne National Laboratory
| ||||||||||||||
ANJ, 10 Aug 2010 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |