[comp.sys.next] Unix Shell version of NXRunAlertPanel

lane@sumex-aim.stanford.edu (Christopher Lane) (06/09/90)

Below is a simple wrapper for the NextStep NXRunAlertPanel routine that
allows it to be used from (interactive) Unix shell scripts (to provide
consistent GUI alert panels across 'C' and shell executables ;-).

The program, Alert, takes the message to display and three button labels
as arguments.  All arguments are optional--buttons are not drawn if labels
are not supplied.  The return value of NXRunAlertPanel is remapped into
something useful for shell scripts; for the first (default) button (first
button argument but first from the right on the panel), it returns '0'
(success), otherwise '1' or '2' for the other buttons and '3' on error.

Thus, you can do things like:

    Alert 'Are you sure?' 'Yes' 'No' 'Help'
    if ( $status == 2 ) ...
		
I didn't include access to the 'printf' features of NXRunAlertPanel as you
can provide the same functionality from within the script language, eg:

    Alert "Using the current time (`date`)"

The 'title' of the alert panel is taken from the title of the program, so
you can have a 'Warning' panel by doing 'ln -s Alert Warning' where Alert
is stored (eg. /usr/local/bin).  Comments and/or suggestions welcome,

- Christopher


/* File:	Alert.m - (Interactive) Unix shell version of NXRunAlertPanel
 *
 * By:		Christopher Lane (lane@sumex-aim.stanford.edu)
 *
 * Date:	7 June 1990
 *
 * Copyright:	1990 by The Leland Stanford Junior University.
 *
 * Compile:	cc -O -g -o Alert Alert.m -lNeXT_s -lsys_s
 */

#import <stdlib.h>
#import <appkit/Panel.h>
#import <appkit/Application.h>

typedef enum {TITLE, MESSAGE, DEFAULT, ALTERNATE, OTHER, ARGC} ARGUMENTS;
typedef enum {ALERTDEFAULT = EXIT_SUCCESS, ALERTALTERNATE, ALERTOTHER,
	ALERTERROR} RESULTS;

void main(int argc, char *argv[])
{
	int result;
	
	NXApp = [Application new];
	
	result = NXRunAlertPanel(
		(argc > TITLE) ? argv[TITLE] : NULL,
		(argc > MESSAGE) ? argv[MESSAGE] : NULL,
		(argc > DEFAULT) ? argv[DEFAULT] : NULL,
		(argc > ALTERNATE) ? argv[ALTERNATE] : NULL,
		(argc > OTHER) ? argv[OTHER] : NULL
		);
			
	(void) [NXApp free];
	
	switch(result){
		case NX_ALERTDEFAULT: exit(ALERTDEFAULT);
		case NX_ALERTALTERNATE: exit(ALERTALTERNATE);
		case NX_ALERTOTHER: exit(ALERTOTHER);
		}
	exit(ALERTERROR);
}
-------

lane@sumex-aim.stanford.edu (Christopher Lane) (06/15/90)

I've FTP'd the (binary) file ShellPanel.tar.Z to the submissions directory of
the cs.orst.edu NeXT archive.

This contains the 'wrapper' for NXRunAlertPanel I posted earlier as well as
similar wrappers for the OpenPanel and SavePanel objects.  These allow you to
invoke 'Open' and 'Save' panels from shell scripts and get back the file
name(s) selected as well as determine if the user selected 'Cancel'.

I've included more detailed information in a README(.rtf) file with the code.

- Christopher
-------