Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > inter-app communincation

inter-app communincation
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 15, 2003, 10:28 PM
 
Im writting 2 separate applications and one of these applications needs to be able to execute a method in the other. Im not exactly sure which route I should take to accomplish this task. I figure I can either make the the target application applescriptable or I can use distributed objects. Each of these two ideas seem to have limitations (perhaps not. part of the reason for this post)

applescript method.

app "a" sends an applescript event to app "b" this event needs to pass a string variable to app "b". it would look something like this i suppose.

tell application "a";
activate;
doMethod with argument "12345";
end tell;

where app "b" has a method like:

- doMethod:(NSString *)theArg

distributed object method.

Im not really to up to speed on distributed objects. questions i have are, what if the app that i need to talk to isnt running? will it be run for me? do i have to do something to check to see if it is indeed running first and then do the method?

another idea i just had is that i could write directly to the defaults of app "b" and then tell app a to read the defaults back in. is there some way to see from with in app "b" that the defaults have changed and to then have app "b" re-read its defaults? that would be kinda easy to do. With app "a" I write directly to app "b" defaults, not caring whether app "b" is running. But if app "b" IS running and the defaults are changed, app "b" re-reads its defaults thus populating my apps gui with the new info.

does this make any sense? are any of these ideas valid? the third idea up there that bypasses both applescript and distributed objects seems pretty tasty. any ideas y'all?
(Last edited by 3R1C; Nov 10, 2003 at 10:04 PM. )
3R1C
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
May 15, 2003, 10:58 PM
 
AppleEvents are designed just for this purpose, and AppleScript is the easiest way to implement AppleEvents, IMO.

PS: You probably don't want the activate command in your example (that brings the application to the front). With AppleScript, if the application isn't active, merely referring to it will generally cause it to launch automatically.
     
Banned
Join Date: Apr 2002
Location: -
Status: Offline
Reply With Quote
May 15, 2003, 11:24 PM
 
Originally posted by 3R1C:
Im writting 2 separate applications and one of these applications needs to be able to execute a method in the other. Im not exactly sure which route I should take to accomplish this task. I figure I can either make the the target application applescriptable or I can use distributed objects. Each of these two ideas seem to have limitations (perhaps not. part of the reason for this post)

applescript method.

app "a" sends an applescript event to app "b" this event needs to pass a string variable to app "b". it would look something like this i suppose.

tell application "a";
activate;
doMethod with argument "12345";
end tell;

where app "b" has a method like:

- doMethodNSString *)theArg

distributed object method.

Im not really to up to speed on distributed objects. questions i have are, what if the app that i need to talk to isnt running? will it be run for me? do i have to do something to check to see if it is indeed running first and then do the method?

another idea i just had is that i could write directly to the defaults of app "b" and then tell app a to read the defaults back in. is there some way to see from with in app "b" that the defaults have changed and to then have app "b" re-read its defaults? that would be kinda easy to do. With app "a" I write directly to app "b" defaults, not caring whether app "b" is running. But if app "b" IS running and the defaults are changed, app "b" re-reads its defaults thus populating my apps gui with the new info.

does this make any sense? are any of these ideas valid? the third idea up there that bypasses both applescript and distributed objects seems pretty tasty. any ideas y'all?
Well DO seems to be the right choice, IMHO. There are articles on that topic @ cocoadev.com

Otherwise... if the 2nd app is a "tool" (e.g. no interface) well you could use NSTask to launch it with args and stuff....
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
May 16, 2003, 08:09 AM
 
While Apple Events are probably the simplest answer, you could use an NSDistributedNotification. I don't know that it would be any easier/harder, but if it's a Cocoa app you could decide to go that route.

Other options include a client-server architecture with something like XML-RPC or SOAP.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:33 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2