System Interaction with SenseTalk

These commands and functions let your SenseTalk script interact with the system where the script is running, launch other programs, open files in other programs, or run system commands through the UNIX shell.

Open Command

Behavior: Starts another program, or opens a file with another program on the machine where your script is running. The most common use of this command is to open a file generated by the script, such as opening a text file in a text editor, or a tab-delimited file in a spreadsheet program, so the user can make further changes to it, print it out, etc. If the requested application is already running on the machine where the script is executing, it will be brought to the front, otherwise it will be launched.

Syntax:

open application

open file with application

Example:

open "iTunes"-- launch iTunes on this machine

Example:

open "/tmp/myFile" with "TextEdit"

Note: To open a file for reading or writing its contents within a script, use the open file command.

Shell Command and Function

Behavior: Runs a command in the command-line shell on the local machine and returns the output.

Syntax:

shell command {, optionalParameters}...

get shell( command {, optionalParameters}...)

You can include optional named parameters as a property list at the end of parameters, including:

  • includeErrors: Causes the standard error stream to be included in the output if set to True;
  • notify: an object to notify when the shell task has completed (defaults to ‘me’ if not given and a message is specified);
  • message: Message to send to the notify object when the task completes (defaults to "ShellDone" if not specified);
  • command: The command to execute (this allows a single property list parameter to be used).

If notify or message is specified, the shell command/function returns immediately and the script proceeds. When the shell task finishes, the notification message will be sent to the notify object. The notification message includes 3 parameters: the output, the exit status, and the input command (in order to distinguish between different callbacks). If the script run completes before the task has finished, the result is undefined.

If multiple shell calls are made asynchronously, the resulting callback order might be different than the order in which the calls were made. A faster-running command might complete before a slower command that was called earlier.

Example:

shell "rm /tmp/testfile"

Example:

log shell(command:command, includeErrors:YES)

Example:

put shell("cd /; ls -l") into rootDirectoryList

Example:

get shell(command:theCmd, includeStderr:YES)

shell "grep -i 'foo' */*", notify:me, message:"grepComplete"

Example:

put shell(includeErrors:YES, command:theCMD)

Note: There is a Windows operating system limitation when running shell commands. When you run a shell command on Windows, you won't see any output from the shell command. To resolve this issue, redirect the output of the command by piping the output to a file. After the script completes, manually read the file contents to see the result.

shell "c:\windows\system32\cmd.exe", <</c "C:\Program Files (x86)\adt-bundle-windows-x86_64\sdk\platform-tools\adb" >> && MyCommand && "> someFile.txt"

put file "C:\wherever\someFile.txt"

Tech Talk

The shell command and function both set the result to the exit code of the command that ran. Typically the exit code is 0 when a command runs successfully and some other value when there is a problem, but the exact meaning of the exit code depends on the command that was run.

The command runs on the machine where the script is running. To run a shell command on another machine, you can use one of the shell commands that provides remote access, such as rsh or ssh.

Related Global Property

You can control the default shell application by using the shellCommand global property. For complete information about the initial default shells for each platform as well as how you can change the setting, see the shellCommand.

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant