Mac Developer Library

Developer

Automator Framework Reference AMBundleAction Class Reference

Options
Deployment Target:

On This Page
Language:

AMBundleAction

Conforms To


Import Statement


Swift

import Automator

Objective-C

@import Automator;

Availability


Available in OS X v10.4 and later.

Instances of the AMBundleAction class manage Automator actions that are loadable bundles. Automator loads action bundles from standard locations in the file system: /System/Library/Automator, /Library/Automator, and ~/Library/Automator.

AMBundleAction objects have several important properties:

  • The NSBundle object associated with the action’s physical bundle

  • The action’s view, which holds its user interface

  • A parameters dictionary that reflects the settings in the user interface

When you create a Cocoa Automator Action project in Xcode, the project template includes a custom subclass of AMBundleAction. (This custom class is given the name of the project.) The sole requirement for this custom class is to provide an implementation of runWithInput:error:, which is declared by the superclass AMAction.

Subclassing Notes

As noted in the Overview section, the Xcode project templates for Automator actions includes partially completed header and source files for a custom subclass of AMBundleAction. The name of this custom class is the name of the Xcode project. To complete the implementation of this subclass, you must override runWithInput:error: (declared by AMAction).

Methods to Override

To subclass AMBundleAction, you must override the runWithInput:error: to implement the task performed by the action. If you have added any instance variables, you must override the initWithDefinition:fromArchive: method and the writeToDictionary: method of AMAction to work with them.

  • Sent to the receiver when all objects in its bundle have been unarchived.

    Declaration

    Swift

    func awakeFromBundle()

    Objective-C

    - (void)awakeFromBundle

    Discussion

    This method allows an action object to perform set-up tasks requiring the presence of all bundle objects, such as adding itself as an observer of notifications, dynamically establishing bindings, and dynamically setting targets and actions.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.

  • Initializes and returns an allocated AMBundleAction object.

    Declaration

    Swift

    init!(definition dict: [NSObject : AnyObject]!, fromArchive archived: Bool)

    Objective-C

    - (instancetype)initWithDefinition:(NSDictionary *)dict fromArchive:(BOOL)archived

    Discussion

    The definitions dictionary dict contains configuration information specific to the receiver. If archived is YEStrue, the definitions are coming from an archive. You may examine the definitions dictionary to learn about specific properties and settings of the action, but some of the keys are private to Automator. You should not attempt to change the values in dict, but you may add custom key-value pairs to the definition dictionary by overriding the writeToDictionary: method declared by the superclass, AMAction. If at runtime you need to learn about or change the action’s properties in its information property list (Info.plist), send the appropriate NSDictionary messages to the action bundle’s infoDictionary; for example:

    • [NSDictionary *infoDict = [[self bundle] infoDictionary];
    • NSString *theApp = [infoDict objectForKey:@"AMApplication"];
    • if ([theApp isEqualToString:@"Finder"]) {
    • // do something appropriate
    • }

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.

  • bundle bundle Property

    Returns the receiver’s bundle object.

    Declaration

    Swift

    var bundle: NSBundle! { get }

    Objective-C

    @property(readonly, strong) NSBundle *bundle

    Discussion

    Returns nil if no bundle has been set.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.

    See Also

    – view

  • hasView hasView Property

    Returns whether the receiver has a view associated with it.

    Declaration

    Swift

    var hasView: Bool { get }

    Objective-C

    @property(readonly) BOOL hasView

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.

    See Also

    – view

  • view view Property

    Returns the receiver’s view object.

    Declaration

    Swift

    var view: NSView! { get }

    Objective-C

    @property(readonly, strong) NSView *view

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.

  • Returns the receiver's parameters.

    Declaration

    Swift

    var parameters: NSMutableDictionary!

    Objective-C

    @property(strong) NSMutableDictionary *parameters

    Discussion

    The parameters of an action reflect the choices made and values entered in the action’s user interface. Keys in the parameters dictionary identify specific user-interface objects. If an action uses the Cocoa bindings mechanism, the parameters of an AMBundleAction object are automatically set. You can change the parameters wholesale with setParameters:. Or you can get the current parameters dictionary with the parameters property and update individual parameters.

    Import Statement

    Objective-C

    @import Automator;

    Swift

    import Automator

    Availability

    Available in OS X v10.4 and later.