Path: utzoo!attcan!uunet!samsung!usc!apple!decwrl!shelby!daemon From: lane@sumex-aim.stanford.edu (Christopher Lane) Newsgroups: comp.sys.next Subject: Unix Shell version of NXRunAlertPanel Message-ID: <2010@shelby.Stanford.EDU> Date: 8 Jun 90 18:33:13 GMT Sender: daemon@shelby.Stanford.EDU Lines: 71 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 #import #import 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); } -------