< Previous PageNext Page > Hide TOC

Creating Automator Actions for Apple Remote Desktop

Apple Remote Desktop (ARD) 3 is the latest release of Apple’s desktop management software, enabling administrators to distribute software, manage assets, and remotely administer Mac OS X systems via a network. ARD 3 takes advantage of innovative technologies in Mac OS X Tiger such as Automator.

Automator is built on the concept of actions - discrete tasks such as opening a file, cropping an image, or sending a message. With Automator users can string together a series of actions into a single Automator workflow document. Much like a script, a workflow document can be executed, triggering each action and passing any data generated by the action to the next action in the workflow.

Using the Automator actions installed with ARD and custom actions you create, you can develop workflows to automate repetitive system administration tasks. For example, workflows can distribute software, create detailed software and hardware reports, and remotely configure systems using ARD.

This article is intended for system administrators and developers looking to create their own Automator actions to supplement the actions bundled with ARD. A basic understanding of ARD, Automator, Xcode, AppleScript and the process for creating Automator actions is assumed. For background information about Automator and creating Automator actions see the Automator Programming Guide. For more information about AppleScript see Getting Started with AppleScript.

This topic provides examples and sample code for three types of actions. The first is an action that performs a task provided by ARD. The second combines two actions into one workflow. The third example executes a UNIX or AppleScript command.

Contents:

Example 1: Locking Remote Computer Screens
Example 2: Combining ARD Tasks and UNIX Commands
Example 3: Combining AppleScript and UNIX Commands


Example 1: Locking Remote Computer Screens

Apple Remote Desktop can lock the screen of remote computers, blanking their screens and preventing user input. The following sample code, written in AppleScript, allows you to build an Automator action that uses ARD to lock remote screens. In order to reduce the length of some of the lines in the examples a line continuation character (¬) is used. The use of line continuation characters is optional. To create a line continuation character in the AppleScript Script Editor, press Option-Return on your keyboard.

on run {these_computers, parameters}
    if the class of these_computers is not list then set these_computers to¬
    these_computers as list
 
    set task_name to "Lock All Screens"
 
    set screen_message to (|screenMessage| of parameters) as Unicode text
 
    tell application "Remote Desktop"
        set this_task to make new lock screen task with properties¬
        {name:task_name, showing output:false, message:screen_message}
        execute this_task on these_computers
    end tell
 
    return these_computers
end run

This example contains the on run hander, which is part of the standard template for all Automator actions and contains the statements that are evaluated when the script runs. It expects two things: a list of computers and a parameter containing the selections made in the action's user interface. For more information about extracting the stored parameters see Implementing an AppleScript Action.

When the on run handler executes, it first checks to make sure the these_computers input parameter is indeed a list. If it is not then it is made into a list.

The third statement creates a variable called screen_message that contains the text that will be displayed on the remote screen when it is locked. This text is extracted from the Automator action's user interface using parameters and is formatted as Unicode text.

For instance, you might design a UI for this action in Interface Builder like this, with the text field bound to a parameter called screenMessage:


image: ../Art/ard_ss1.jpg

Once the necessary variables are initialized, Apple Remote Desktop is used (by way of the tell application statement) to create a task called this_task as a lock screen task. The task is initialized with variables from the script and values from the script's input parameters and executed.

Finally the handler returns the list of computers it received in the on run handler. Though the script did not generate new data, it should return its original input so the list of computers it received can be passed to the next action in the workflow for additional processing.

Example 2: Combining ARD Tasks and UNIX Commands

This example combines two Apple Remote Desktop tasks (Copy Items and Send UNIX) into a single Automator action. When activated, it will change a remote computer's desktop picture to be the same as the ARD administrator's desktop picture.

The AppleScript in the example makes use of double quotes, which must be escaped to be used in a UNIX shell script. When double quotes are used in your AppleScript, type a backslash (\) character immediately before the double quote.

on run {these_computers, parameters}
    if the class of these_computers is not list then set¬
    these_computers to these_computers as list
    set first_task_name to "Copy Desktop Image"
    set second_task_name to "Replace Remote Desktop Image"
    tell application "Finder"
        set this_image to ((get the desktop picture) as alias)
        set the image_name to the name of this_image
    end tell
    tell application "Remote Desktop"
        set this_task to make new copy items task with properties¬
        {name:first_task_name, showing output:false,¬
        location:current users desktop folder, copy items:¬
        {this_image}, bandwidth limit:0, conflict¬
        resolution:replace, should open:false, ownership:current¬
        console user}
        execute this_task on these_computers
    end tell
 
    set the UNIX_script to "osascript -e 'tell application¬
    \"Finder\"
    set this_image to document file \"" & image_name & "\" ¬
    of the desktop
    set this_image to move this_image to (path to pictures folder)¬
    with replacing
    set the desktop picture to this_image
end tell'"
 
tell application "Remote Desktop"
    set this_task to make new send unix command task with¬
    properties {name:second_task_name, showing output:false,¬
    script:UNIX_script}
    execute this_task on these_computers
end tell
    return these_computers
end run

This example uses the same structure as the first example. In the script the Finder is asked to create an AppleScript alias to the current desktop picture, this alias is then used by the Remote Desktop copy items task. Finally, a UNIX script is used to set the image as the desktop picture. The UNIX command osascript executes an AppleScript as if it were a shell script.

Example 3: Combining AppleScript and UNIX Commands

Apple Remote Desktop allows administrators to execute a UNIX command or shell script on remote systems. The osascript command allows developers to embed AppleScript commands in a UNIX shell script. These two technologies allow administrators to perform a wide range of tasks that are not provided as standard features of ARD. The following example code shows how to combine "Send UNIX Command" and AppleScript functionality.

on run {these_computers, parameters}
    if the class of these_computers is not list then set these_computers to¬
    these_computers as list
    set task_name to "Clean Desktop"
 
    set the UNIX_script to "osascript -e 'tell application \"Finder\" to¬
    delete every item of the desktop whose class is not disk'"
 
    tell application "Remote Desktop"
        set this_task to make new send unix command task with properties¬
        {name:task_name, showing output:false, script:UNIX_script}
        execute this_task on these_computers
    end tell
    return these_computers
end run

This example is very similar to the first example, but uses a UNIX script in place of the lock screen task. In this case the AppleScript command will delete every item on the Desktop of remote systems, excluding mounted volumes.



< Previous PageNext Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-05-23)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.