Solaris Common Desktop Environment: Advanced User's and System Administrator's Guide

Chapter 12 Creating Actions Manually

There are two ways to create actions:

Creating an action manually requires you to edit a database file. This chapter describes how to manually create action definitions.

Reasons You Must Create an Action Manually

There are three basic types of actions:

The Create Action tool is designed to create certain types of COMMAND and MAP actions. All TT_MSG actions must be created manually.

For more information, see Limitations of Create Action.

COMMAND Actions

A command action executes a command that starts an application or utility, runs a shell script, or executes an operating system command. The definition of the action includes the command to be executed (the EXEC_STRING).

The Create Action tool can be used to create the most common types of command actions. However, there may be some situations where you must create the action manually; for example, you must create a COMMAND action manually if the action specifies:

MAP Actions

A map action is an action that is ``mapped'' to another action rather than directly specifying a command or ToolTalk message

Mapping provides the ability to specify alternative names for actions. For example, a built-in command action named IconEditor starts Icon Editor. The database also includes an Open action, restricted in the definition to bitmap and pixmap files (by the ARG_TYPE field), that is mapped to the IconEditor action. This lets the user start Icon Editor by selecting a bitmap or pixmap file in File Manager and then choosing Open from the Selected menu.

Create Action provides limited mapping for Open and Print actions. All other map actions must be created manually.

TT_MSG (ToolTalk Message) Actions

TT_MSG actions send a ToolTalk message. All TT_MSG actions must be created manually.

Creating an Action Manually: General Steps

This section explains how to create a configuration file for an action definition.

Configuration Files for Actions

Configuration files containing action definitions must meet these requirements:

For information on modifying the actions/data types search path, see Setting the Value of a Search Path.

To Create an Action Manually

  1. Open an existing database file or create a new one.

    See the previous section, Configuration Files for Actions.

  2. Create the action definition using the syntax:

    	ACTION action_name
     	{
     		TYPE		action_type
     		action_field
     		…
     	}

    where:

    action_name—name used to run the action.

    action_type—COMMAND (default), MAP, or TT_MSG.

    action_field—one of the required or optional fields for this type of action. All fields consist of a keyword and a value.

    Many of the action fields are covered in this chapter. For more information, see the dtactionfile(4) man page.

  3. Save the file.

  4. If you want the action icon to have a unique image, create the icons for the action. The default location for icons is:

    • Personal icons: HomeDirectory/.dt/icons

  5. Double-click Reload Actions in the Desktop_Tools application group.

  6. Create an action file for the action. The action file creates an icon in File Manager or Application Manager that represents the action. (If the action is written to start an application, the icon is called an application icon.)

    To create the action file, create an executable file with the same name as action_name. You can put the file in any directory to which you have write permission. You can create as many action files as you like.

Example of Creating a COMMAND Action

The following steps create a personal action that starts a fax application on remote system AppServerA. The command for starting the fax application is:

/usr/fax/bin/faxcompose [filename]
  1. Create the file HomeDirectory/.dt/types/Fax.dt.

  2. Put the following action definition into the file:

    	ACTION FaxComposer
     	{
     		TYPE					COMMAND
     		ICON					fax
     		WINDOW_TYPE			NO_STDIO
     		EXEC_STRING			/usr/fax/bin/faxcompose -c %Arg_1%
     		EXEC_HOST     	 	AppServerA
     		DESCRIPTION    	Runs the fax composer
    	}

    The WINDOW_TYPE and EXEC_STRING fields describe the behavior of the action.

    WINDOW_TYPE—the NO_STDIO keyword specifies that the action does not have to run in a terminal emulator window.

    See Specifying the Window Support for the Action.

    EXEC_STRING—the syntax %Arg_1% accepts a dropped file. If the action icon is double-clicked, the action opens an empty fax composer window.

    See Building the Execution String for a COMMAND Action.

  3. Save the file.

  4. Use Icon Editor to create the following icon image files in the HomeDirectory/.dt/icons directory:

    • fax.m.pm, size 32 by 32 pixels

    • fax.t.pm, size 16 by 16 pixels

  5. Double-click Reload Actions in the Desktop_Tools application group.

  6. Create an executable file named FaxComposer in a directory to which you have write permission (for example, your home directory).

Example of Creating a MAP Action

Suppose most of the files you fax are created with Text Editor and are of data type TEXTFILE (files named *.txt).

These steps add a ``Fax'' menu item to the data type's Selected menu.

  1. Open the file HomeDirectory/.dt/types/Fax.dt that was created in the previous example.

  2. Add this map action definition to the file:

    	ACTION Fax
     	{
     		ARG_TYPE			TEXTFILE
     		TYPE				MAP
     		MAP_ACTION		FaxComposer
     	} 
  3. Save the file.

  4. Copy the data attributes definition for TEXTFILE from /usr/dt/appconfig/types/language/dtpad.dt to a new file HomeDirectory/.dt/types/textfile.dt. Add the Fax action to the ACTIONS field.

    	DATA_ATTRIBUTES TEXTFILE
     	{
     		ACTIONS			Open,Print,Fax
     		ICON				Dtpenpd
     		…
     	}
  5. Save the file.

  6. Open Application Manager and double-click Reload Actions in the Desktop_Tools application group.

To Reload the Actions/Data Types Database

In order for new or edited action definitions to take effect, the desktop must reread the database.

    Open the Desktop_Tools application group and double-click Reload Actions.

    Or, execute the command:

    	dtaction ReloadActions

    ReloadActions is the name of the action whose icon is labeled ``Reload Actions.''

    The actions database is also reread when the user:

    • Logs in

    • Restarts the Workspace Manager

    • Saves an action in the Create Action window by choosing Save from the File menu

Creating an Action File (Icon) for an Action

An action file is a file created to provide a visual representation of the action in File Manager or Application Manager.

Figure 12–1 Action files (action icons) in Application Manager

Graphic

Since an action file's icon represents an action, it is sometimes called an action icon. If the underlying action starts an application, the action file icon is called an application icon.

Double-clicking the action icon runs the action. The action icon may also be a drop zone.

To Create an Action File (Action Icon)

    Create an executable file with the same name as the action name. The content of the file does not matter.

For example, if the action definition is:

ACTION  MyFavoriteApp
 {
 	EXEC_STRING				Mfa -file %Arg_1%
 	DESCRIPTION				Runs MyFavoriteApp
 	ICON						Mfapp
 }

then the action file would be an executable file named MyFavoriteApp. In File Manager and Application Manager, the MyFavoriteApp file would use the icon image Mfapp.size.type. Double-clicking MyFavoriteApp's icon would run the action's execution string, and the icon's On Item help would be the contents of the DESCRIPTION field (“runs MyFavoriteApp”).

Action Labels

If the action definition includes the LABEL field, the action file will be labeled in File Manager and Application Manager with the contents of this field rather than the file name (action_name). For example, if the action definition includes:

ACTION  MyFavoriteApp
 {
 	LABEL      Favorite Application
 	…
 }

then the action icon will be labeled ``Favorite Application.''

Specifying the Icon Image Used by an Action

Use the ICON field to specify the icon used in File Manager and Application Manager for the action icons created for the action.

If you do not specify an icon, the system uses the default action icon image files /usr/dt/appconfig/icons/language/Dtactn.*.

Figure 12–2 Default action icon image

Graphic

The default action icon can be changed using the resource:

*actionIcon:    icon_file_name

where icon_file_name can be a base name or absolute path.

The value of the ICON field can be:

Table 12–1 Icon Names and Sizes for Action Icons

Size in Pixels 

Bitmap Name 

Pixmap Name 

48 by 48 

name.l.bm

name.l.pm

32 by 32 

name.m.bm

name.m.pm

16 by 16 

name.t.bm

name.t.pm

To Modify an Existing Action Definition

You can modify any of the actions available on your system, including built-in actions.


Note –

Use caution when modifying the built-in action database. The built-in actions are designed to work well with the desktop applications.


  1. Locate the definition of the action you want to modify.

    The default locations for action definitions are:

    • Built-in actions: /usr/dt/appconfig/types/language

    • System-wide actions: /etc/dt/appconfig/types/language

    • Personal actions: HomeDirectory/.dt/types

      Your system might include additional locations. To see a list of the locations your system uses for actions, type the command:

      	dtsearchpath -v
      

      Your system uses the directories listed under DTDATABASESEARCHPATH.

  2. If necessary, copy the text of the action definition to a new or existing file in one of these directories:

    • System-wide actions: /etc/dt/appconfig/types/language

    • Personal actions: HomeDirectory/.dt/types

      You must copy built-in actions, since you should not edit files in the /usr/dt/appconfig/types/language directory.

  3. Edit the action definition.

  4. When you are done editing, save the file.

  5. Double-click Reload Actions in the Desktop_Tools application group.

Precedence in Action Definitions

When the user invokes an action, the system searches the database for a matching action name. When more than one action exists with that name, the system uses precedence rules to decide which one to use.

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:

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:

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

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

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:

Creating an Action that Prompts for a Non-File Argument

Use this syntax for the non-file parameter:

%"prompt"%

or

%(String)"prompt"%

(String) is optional, since quoted text is interpreted, by default, as string data. This syntax displays a dialog box that prompts for non-file data; do not use this syntax when prompting for a file name.

For example, this execution string runs the xwd command and prompts for a value to be added to each pixel:

EXEC_STRING xwd -add %"Add value:"% -out %Arg_1"Filename:"%

Interpreting a File Argument as a String

Use this syntax for the argument:

%(String)Arg_n%

For example, this execution string prints a file with a banner containing the file name, using the command lp -tbanner filename.

EXEC_STRING lp -t%(String)Arg_1% %(File)Arg_1"File to print:"%

Providing Shell Capabilities in an Action

Specify the shell in the execution string:

/bin/sh -c 'command'
/bin/ksh -c 'command'
/bin/csh -c 'command'

Examples

Creating COMMAND Actions for Multiple File Arguments

There are three ways for actions to handle multiple file arguments:

Creating an Action for Non-Interchangeable Arguments

Use one of the following syntax conventions:

Creating an Action with Interchangeable File Arguments

Use one of the following syntax conventions:

Examples

Creating an Action for Multiple Dropped Files

To accept multiple dropped file arguments and execute a command line in the form:

command file 1 file 2

use the syntax:

%Args%

Examples

Windowing Support and Terminal Emulators for COMMAND Actions

There are several ways that COMMAND actions support windows on the desktop.

Specifying the Window Support for the Action

Use the WINDOW_TYPE field to specify the type of windowing support required by the action as shown in Table 12–2.

Table 12–2 WINDOW_TYPE Field and Windowing Support Provided

WINDOW_TYPE

Windowing Support Provided 

NO_STDIO

None. Use NO_STDIO if the application has its own window, or if the command has no visible output.

PERM_TERMINAL

Permanent terminal emulator window. The action opens a terminal window that remains open until the user explicitly closes it. The user can enter data into the window. Use with commands that take some input, produce some output, then terminate (for example, ls directory).

TERMINAL

Temporary terminal emulator window. The action opens a terminal window that closes as soon as the command is completed. Use with full-screen commands (for example, vi).

Specifying Command-Line Options for the Terminal Emulator

Use the TERM_OPTS field in the action definition to specify command-line options for the terminal emulator.

For example, the following action prompts for the execution host:

ACTION OpenTermOnSystemUserChooses
 {
 	WINDOW_TYPE					PERM_TERMINAL
 	EXEC_HOST    				%(String)"Remote terminal on:"%
 	TERM_OPTS    				-title %(String)"Window title:"%
 	EXEC_STRING  				$SHELL
 }

Specifying a Different Default Terminal Emulator

The default terminal emulator used by actions is dtterm. You can change this to another terminal emulator. The default terminal emulator is used when the action does not explicitly specify a terminal emulator to use.

The terminal emulator used by actions must have these command-line options:

Restricting Actions to Certain Arguments

Restricting an action to a particular type of argument refines the action. For example, you should restrict an action that invokes a viewer for PostScript files to only PostScript file arguments; with the restriction, the action will return an error dialog if a non-PostScript file is specified.

You can restrict actions based on:

Restricting an Action to a Specified Data Type

Use the ARG_TYPE field to specify the data types for which the action is valid. Use the data attribute name.

You can enter a list of data types; separate the entries with commas.

For example, the following action definition assumes a GIF data type has been created.

ACTION Open_Gif
 {
 	TYPE					COMMAND
 	LABEL					"Display Gif"
 	WINDOW_TYPE			NO_STDIO
 	ARG_TYPE				Gif
 	ICON					xgif
 	DESCRIPTION			Displays gif files
 	EXEC_STRING			xgif
 }

Restricting an Action Based on the Number of Arguments

Use the ARG_COUNT field to specify the number of arguments the action can accept. Valid values are:

* (Default)—any number of arguments. Other values have precedence over *.

n—any non-negative integer, including 0.

>n—more than n arguments.

<n—fewer than n arguments.

One use for ARG_COUNT is to provide different action icon behavior, depending on whether the user double-clicks the icon or drops a file on it. See the next section, “To Provide Different Double-Click and Drop Behavior.”

To Provide Different Double-Click and Drop Behavior

Use this procedure to create an action that accepts a dropped file but does not prompt for a file when the action icon is double-clicked.

  1. Create an action definition for the double-click functionality.

    Use the ARG_COUNT field to specify 0 arguments. Use a syntax for the EXEC_STRING that does not accept a dropped argument.

  2. Create a second action definition for the drop functionality.

    Use the ARG_COUNT field to specify >0 argument. Use a syntax for the EXEC_STRING that accepts a dropped file.

    For example, suppose the following two command lines can be used to start an editor named vedit:

    • To start the editor with no file argument:

      	vedit
    • To start the editor with a file argument that is opened as a read-only document:

      	vedit -R filename
      

      The following two actions create drop and double-click functionality for an action named Vedit. The first action has precedence when the database is searched for a match, since ARG_COUNT 0 is more specific than the implied ARG_COUNT * of the drop functionality definition.

      # Double-click functionality
       ACTION Vedit
       {
       	TYPE						COMMAND
       	ARG_COUNT				0
       	WINDOW_TYPE				PERM_TERMINAL
       	EXEC_STRING				vedit
       }
      
       # Drop functionality
       ACTION Vedit
       {
       	TYPE						COMMAND
       	WINDOW_TYPE				PERM_TERMINAL
       	EXEC_STRING				vedit -R %Arg_1%
       }

Restricting an Action Based on the Mode of the Argument

Use the ARG_MODE field to specify the read/write mode of the argument. Valid values are:

* (Default)—any mode

!w—non-writable

w—writable

Creating Actions that Run Applications on Remote Systems

When discussing actions and remote execution, there are two terms that are used frequently:

database host—the system containing the action definition

execution host—the system where the executable runs

In most situations, actions and their applications are located on the same system; since the default execution host for an action is the database host, no special syntax is required.

However, when the execution host is different from the database host, the action definition must specify where the execution string should be run.

The ability to locate actions and applications on different systems is part of the client/server architecture of the desktop. For a more in-depth discussion of networked applications, see Administering Application Services.

Creating an Action that Runs a Remote Application

Use the EXEC_HOST field in the action definition to specify the location of the application.

Valid values for EXEC_HOST are:

%DatabaseHost%—the host where the action is defined.

%LocalHost%—the host where the action is invoked (the session server).

%DisplayHost%—the host running the X server (not allowed for X terminals).

%SessionHost%—the host where the controlling Login Manager is running.

hostname—the named host. Use this value for environments in which the action should always be invoked on one particular host.

%"prompt"%—prompts the user for the host name each time the action is invoked.

The default value is %DatabaseHost%, %LocalHost%. Thus, when the EXEC_HOST field is omitted, the action first attempts to run the command on the host containing the action definition. If this fails, the action attempts to run the command on the session server.

Examples

Using Variables in Action and Data Type Definitions

You can include string variables and environment variables in action and data type definition files.

Using String Variables in an Action

A string variable definition remains in effect from the location of the definition to the end of the file. There are no global string variables for the database.

If a string variable and environment variable have the same name, the string variable has precedence.

To Define a String Variable

    Use the syntax:

	set variable_name=value

Variable names can contain any alphanumeric characters and underscore (_). Each variable definition must be on a separate line.

For example:

set Remote_Application_Server=sysapp
set Remote_File_Server=sysdata

To Reference a String Variable

    Use the syntax:

	$[{]variable_name[}]

For example:

EXEC-HOST			$Remote_Application_Server
CWD					/net/${Remote_File_Server}/doc/project

Using Environment Variables in Actions and Data Types

    Reference an environment variable using the syntax:

	$[{]variable[}]. 

The variable is expanded (replaced by its value) when the database is loaded. If a string variable and environment variable have the same name, the string variable has precedence.

For example, this execution string prints a file with a banner containing the login name.

EXEC-STRING lp -t$LOGNAME %(File)Arg_1%

Invoking Actions from a Command Line

The desktop provides the dtaction command for running actions from a command line. You can use dtaction to run actions from:

Syntax of dtaction

dtaction [-user user_name] [-execHost hostname] \
 action_name [argument [argument]…]

-user user_name—provides the ability to run the action as a different user. If dtaction is invoked by a user other than user_name, a prompt is displayed for the password.

-execHost hostname—for COMMAND actions only; specifies the host on which the command will be run.

argument—arguments to the action; usually file arguments.

The dtaction client has additional command-line options. For more information, see the dtaction(1) man page.

Creating an Action that Runs Another Action

Use dtaction in the EXEC_STRING of the action.

For example, the following action uses a built-in action named Spell (the action is labeled ``Check Spelling'' in Application Manager). The new action runs Text Editor and the Spell action, displaying the spelling errors in a separate terminal emulator window.

ACTION EditAndSpell
 {
 	WINDOW_TYPE				NO_STDIO
 	EXEC_STRING				/bin/sh -c 'dtaction Spell \
 								%Arg_1"File:"%; dtpad %Arg_1%'
 }

Creating an Action that Runs as a Different User

Use the following syntax in the EXEC_STRING:

EXEC_STRING   dtaction -user user_name action_name [file_argument]

The new user (user_name) must have display access to the system through one of the following mechanisms:

Creating Localized Actions

The search path for data types includes language-dependent locations. The desktop uses the value of LANG to determine the locations searched for data type definitions.

Locations for Localized Actions

Localized action definitions must be placed in the proper language-dependent directories along the actions search path.

The default search path is:

To Localize an Existing Action

  1. Create a file in the appropriate language-dependent directory (for example, in /etc/dt/appconfig/types/japanese) .

  2. Copy the action definition to the language-dependent configuration file.

    For example, you might copy an action definition from

    	app_root/dt/appconfig/types/C/file.dt

    to

    	app_root/dt/appconfig/types/japanese/newfile.dt
  3. Add a LABEL field or modify the existing LABEL field.

    	LABEL			string
    

    Application Manager and File Manager use the label string to identify the action's icon.

  4. Localize any of the following fields in the action definition:

    • For localized icons: ICON

    • For localized On Item help: DESCRIPTION

    • For localized prompts: any quoted text in the EXEC_STRING

Creating Actions for ToolTalk Applications


Note –

The following information applies only to applications that support ToolTalk messaging.


Use the action type TT_MSG to create an action that sends a ToolTalk message.

ACTION action_name
{
 	TYPE		TT_MSG  
 	… 
	}

addressing and disposition Fields

Unsupported Messages

The following are not supported by TT_MSG-type actions:

Keywords for TT_MSG Actions

Table 12–3shows the keyword and usage for TT_MSG actions.

Table 12–3 TT_MSG Action Keywords and Usage

Keyword 

Use 

TT_CLASS

Defines the value of the ToolTalk class message field 

TT_SCOPE

Defines the value of the ToolTalk scope message field 

TT_OPERATION

Defines the value of the ToolTalk operation message field 

TT_FILE

Defines the value of the ToolTalk file message field 

TT_ARGn_MODE

Defines the value of the ToolTalk mode attribute for the nth message argument

TT_ARGn_VTYPE

Defines the value of the ToolTalk vtype attribute of the nth message argument

TT_ARGn_VALUE

Defines the value of the nth message argument