Mac Developer Library

Developer

Automator Framework Reference AMWorkflow Class Reference

Options
Deployment Target:

On This Page
Language:

AMWorkflow

Inheritance


Conforms To


Import Statement


Swift

import Automator

Objective-C

@import Automator;

Availability


Available in OS X v10.5 and later.

The AMWorkflow class lets you use an Automator workflow in your application. You can display a workflow with an instance of AMWorkflowView and control its operation with an instance of AMWorkflowController.

A workflow consists of one or more actions (discrete tasks), which together can perform complex automation tasks. Your application can use workflows to package its own features and to take advantage of features provided by other applications. You create actions with Xcode, while you create workflows with the Automator application.

You can load and run a workflow with minimal overhead by using the AMWorkflow class method runWorkflowAtURL:withInput:error:. However, in situations where you need greater control, such as the ability to start and stop the workflow, you can use an instance of the AMWorkflowController class instead. In that case, you’ll have to create and initialize both a workflow and a workflow controller object.

In either case, the workflow is run in a separate process so that any actions it contains are executed in a separate memory space. That helps to insulate your application from crashes, memory leaks, or exceptions that might occur from running the actions in the workflow.

  • Loads and runs the specified workflow file.

    Declaration

    Swift

    class func runWorkflowAtURL(_ fileURL: NSURL!, withInput input: AnyObject!, error error: NSErrorPointer) -> AnyObject!

    Objective-C

    + (id)runWorkflowAtURL:(NSURL *)fileURL withInput:(id)input error:(NSError **)error

    Parameters

    fileURL

    URL that specifies the location of a workflow file.

    input

    Specifies the input for the first action in the workflow. Pass nil if the first action doesn’t need input.

    error

    If no workflow is found or if an error occurs in initializing or running it, upon return contains an instance of NSError that describes the problem.

    Return Value

    On error, returns nil. Otherwise, returns the output of the last action in the workflow. Your application may need to convert the data to a desired type.

    Discussion

    Use this method to run a workflow without the overhead of performing a separate allocation, setting up a workflow controller, and so on. In situations where you need greater control, such as the ability to start and stop the workflow, use an instance of the AMWorkflowController class instead.

    The workflow is run in a separate process so that any actions it contains are executed in a separate memory space. This helps to insulate the application from crashes, memory leaks, or exceptions that might occur from running the actions in the workflow.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.5 and later.

  • Creates and initializes a workflow based on the contents of the specified file.

    Declaration

    Swift

    init!(contentsOfURL fileURL: NSURL!, error outError: NSErrorPointer)

    Objective-C

    - (instancetype)initWithContentsOfURL:(NSURL *)fileURL error:(NSError **)outError

    Parameters

    fileURL

    URL that specifies the location of a workflow file.

    outError

    If the workflow file can’t be found, or if an error occurs in initializing the workflow, upon return contains an instance of NSError that describes the problem.

    Return Value

    The initialized workflow object. On error, returns nil.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.5 and later.

  • Writes the workflow to the specified file.

    Declaration

    Swift

    func writeToURL(_ fileURL: NSURL!, error outError: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)writeToURL:(NSURL *)fileURL error:(NSError **)outError

    Parameters

    fileURL

    URL that specifies the file location to write the workflow.

    outError

    If the workflow file can’t be written, upon return, contains an instance of NSError that describes the problem.

    Return Value

    YEStrue if the workflow was successfully written; otherwise NOfalse.

    Discussion

    You might want to save the workflow, for example, because you have made changes to a variable it contains.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.5 and later.

  • input input Property

    Returns the input data that is passed to the first action in the workflow.

    Declaration

    Swift

    var input: AnyObject!

    Objective-C

    @property(readwrite, retain) id input

    Return Value

    The input for the first action in the workflow. Should be a data type the action can use, or a type that can be converted to one the action can use. Use setInput: to set the input data for the workflow.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.5 and later.

  • output output Property

    Returns the output data that is provided by the last action in the workflow.

    Declaration

    Swift

    var output: AnyObject! { get }

    Objective-C

    @property(readonly, retain) id output

    Return Value

    The output for the for last action in the workflow.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.6 and later.

    See Also

    input

  • Sets the value of the workflow variable with the specified name.

    Declaration

    Swift

    func setValue(_ value: AnyObject!, forVariableWithName variableName: String!) -> Bool

    Objective-C

    - (BOOL)setValue:(id)value forVariableWithName:(NSString *)variableName

    Parameters

    value

    The value to set for the named variable.

    variableName

    The name of a variable to set the value for.

    Return Value

    YEStrue if variableName was found and its value is set; otherwise NOfalse.

    Discussion

    This method does nothing if the variable specified by variableName is not found.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.5 and later.