[comp.sys.next] How can I send a message to a running process?

bchen@ccoroade.caltech.edu (Bing-Qing Chen) (08/28/89)

I understand that when you open a non-executable file in Workspace Manager,
it will send an appOpenFile:type: message to the process that can open
that file if the program is already running or it will start up that program
and send the message to it. Can someone tell me how can I do that from
my program? For example send that message to Preview if I want to preview
a Postscript file.

Thanks.
==============================================================
bchen@wega.caltech.edu or bchen@ccoroada.caltech.edu

dz@pumpkin.ucsb.edu (Daniel James Zerkle) (08/28/89)

In article <11730@cit-vax.Caltech.Edu> bchen@ccoroade.caltech.edu (Bing-Qing Chen) writes:
>I understand that when you open a non-executable file in Workspace Manager,
>it will send an appOpenFile:type: message to the process that can open
>that file if the program is already running or it will start up that program
>and send the message to it. Can someone tell me how can I do that from
>my program? For example send that message to Preview if I want to preview
>a Postscript file.

I had the exact same problem.  Use the following object to do
the job for you.  It takes input from a text field, and it has
a couple of debugging lines in it to show you that everything is
working properly.  Remove those printfs when you are convinced
that it works.

This will actually launch Preview if it is not already running.
There are also several other methods of doing this, but this seems
like the simplest.  See the documentation for the Speaker and Listener
objects for more information (this code is based on an example in the
Speaker documentation).

||||||||||||||||| Cut Here for ||||||||||||||||
vvvvvvvvvvvvvvvvv Displayer.h  vvvvvvvvvvvvvvvv

/* Generated by Interface Builder */

#import <objc/Object.h>
#import <appkit/appkit.h>

@interface Displayer:Object
{
    id	inputForm;
    id	SpeakerId;
    port_t port;
    int returnOk;
    char dfile[500];
}

- setInputForm:anObject;
- doDisplay:sender;

@end

^^^^^^^^^^^^^^^ End of     ^^^^^^^^^^^^^^^^^^^
||||||||||||||| Displayer.h|||||||||||||||||||

||||||||||||||||| Cut Here for ||||||||||||||||
vvvvvvvvvvvvvvvvv Displayer.m  vvvvvvvvvvvvvvvv

/* Generated by Interface Builder */

#import "Displayer.h"

@implementation Displayer

- setInputForm:anObject
{
    inputForm = anObject;
    return self;
}

- doDisplay:sender
{
    printf("Displayer is messaged...\n");
    [inputForm selectTextAt:0];
    
    SpeakerId = [Speaker new];
    port = NXPortFromName("Preview",NULL);
    strcpy(dfile, [inputForm stringValueAt:0]);
    printf("File name is %s.\n",dfile);
    if (port != PORT_NULL)
      {
      printf("messaging the speaker\n");
      [SpeakerId setSendPort:port];
      [SpeakerId openFile:dfile ok:&returnOk];
      }
    [SpeakerId free];
    return self;
}


@end
^^^^^^^^^^^^^^^ End of     ^^^^^^^^^^^^^^^^^^^
||||||||||||||| Displayer.h|||||||||||||||||||
| Dan Zerkle home:(805) 968-4683 morning:961-2434 afternoon:687-0110  |
| dz@cornu.ucsb.edu dz%cornu@ucsbuxa.bitnet ...ucbvax!hub!cornu!dz    |
| Snailmail: 6681 Berkshire Terrace #5, Isla Vista, CA  93117         |
| Disclaimer: If it's wrong or stupid, pretend I didn't do it.        |