Displaying the Running Processes in a list Box and Optionally Closing Some of Them

The “CloseApps” script of the next example displays a list in a dialog window that the user may choose from. The list contains the names of all of the application processes that are running on the computer. These include the programs that have a user interface (e.g., windows and menus that you can interact with) and faceless background applications (FBAs) such as Time Synchronizer or File Sharing Extension. FBAs are programs that work invisibly in the background without interacting with the user. CloseApps is similar to one of the functions of the Windows NT Task Manager utility, which lets you select and shut down a process. Figure 14-5 shows the dialog window displayed by this script. Users may choose one or more processes, and the script will quit the selected programs.

A dialog window displays running processes

The script shown in Example 14-3 uses the choose from list scripting addition and a list of application processes. An application process is an element of the Finder’s application class. You can get a list of all of the currently running app processes simply by requesting all of the Finder’s application processes, as in:

tell app "Finder" to application processes

This phrase does not sound syntactically pleasing, but it does the job. The script gets a list of all application processes with the code:

set applist to application processes

It then creates a list of all of the process names by getting the name property of each member of applist (which contains the application process objects) and adding the name to the list (stored in the namelist variable). An example of the name property of process “Application Switcher” is naturally enough “Application Switcher.” The choose from list scripting addition populates the window with the list of process names in namelist. The user can select one or more of the list names and click the Close Em button, and the script will send a quit Apple event withto each of the selected processes.

Example 14-3. The choose from list Script