Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
12.  Creating Actions Manually Creating an Action Manually: General Steps Precedence in Action Definitions  Previous   Contents   Next 
   
 

Building the Execution String for a COMMAND Action

The minimum requirements for a COMMAND action are two fields--ACTION and EXEC_STRING.

ACTION action_name
 {
     EXEC_STRING execution_string
 }

The execution string is the most important part of a COMMAND action definition. It uses syntax similar to the command line you would execute in a Terminal window but includes additional syntax for handling file and string arguments.

General Features of Execution Strings

Execution strings may include:

  • File and non-file arguments

  • Shell syntax

  • Absolute paths or names of executables

Action Arguments

An argument is information required by a command or application for it to run properly. For example, consider the command line you could use to open a file in Text Editor:

dtpad filename

In this command, filename is a file argument of the dtpad command.

Actions, like applications and commands, can have arguments. There are two types of data that a COMMAND action can use:

  • Files

  • String data

Using Shells in Execution Strings

The execution string is executed directly, rather than through a shell. However, you can explicitly invoke a shell in the execution string.

For example:

EXEC_STRING				\
 		/bin/sh -c \
 		'tar -tvf %(File)Arg_1% 2>&1 | \${PAGER:-more};\
 		echo "\\n*** Select Close from the Window menu to close ***"'

Name or Absolute Path of the Executable

If your application is located in a directory listed in the PATH variable, you can use the simple executable name. If the application is elsewhere, you must use the absolute path to the executable file.

Creating an Action that Uses No Arguments

Use the same syntax for the EXEC_STRING that you would use to start the application from a command line.

Examples

  • This execution string is part of an action that starts the X client xcutsel.

    EXEC_STRING xcutsel
  • This execution string starts the client xclock with a digital clock. The command line includes a command-line option but requires no arguments.

    EXEC_STRING xclock -digital

Creating an Action that Accepts a Dropped File

Use this syntax for the file argument:

%Arg_n%

or

%(File)Arg_n%

(File) is optional, since arguments supplied to Arg_n are assumed (by default) to be files. (See "Interpreting a File Argument as a String" for use of the %(String)Arg_n% syntax.)

This syntax lets the user drop a data file object on the action icon to start the action with that file argument. It substitutes the nth argument into the command line. The file can be a local or remote file.

Examples

  • This execution string executes wc -w using a dropped file as the -load parameter.

    	EXEC_STRING wc -w %Arg_1%
  • This example shows a portion of a definition for an action that works only with directory arguments. When a directory is dropped on the action icon, the action displays a list of all the files in the directory with read-write permission.

    	ACTION  List_Writable_Files
     	{
     	    ARG_TYPE     FOLDER
     	    EXEC_STRING /bin/sh -c 's -l %Arg_1% | grep rw-'
     	    ...
     	}

Creating an Action that Prompts for a File Argument

Use this syntax for the file argument:

%(File)"prompt"% 

This syntax creates an action that displays a prompt for a file name when the user double-clicks the action icon.

For example, this execution string displays a dialog box that prompts for the file argument of the wc -w command:

EXEC_STRING wc -w %(File)"Count words in file:"%

Creating an Action that Accepts a Dropped File or Prompts for One

Use this syntax for the file argument:

%Arg_n"prompt"%

or

%(File)Arg_n"prompt"%

This syntax produces an action that:

  • Accepts a dropped file as the file argument.

  • Displays a dialog box that prompts for a file name when the user double-clicks the action icon.

    For example, this execution string performs lp -oraw on a dropped file. If the action is started by double-clicking the icon, a dialog box appears prompting for the file name.

    EXEC_STRING lp -oraw %Arg_1"File to print:"%
 
 
 
  Previous   Contents   Next