NSUserUnixTask Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.8 and later.
Declared in
NSUserScriptTask.h

Overview

The NSUserUnixTask class is intended to run unix applications, typically a shell script, from your application. It is intended to execute user-supplied scripts, and will execute them outside of the application's sandbox, if any.

The class is not intended to execute scripts built into an application; for that, use one of the NSTask, NSAppleScript, or AMWorkflow classes. If the application is sandboxed, then the script must be in the NSApplicationScriptsDirectory folder. A sandboxed application may read from, but not write to, this folder.

If you simply need to execute unix scripts without regard to input or output, use NSUserScriptTask, which can execute any of the specific types. If you need specific control over the input to, or output from, or the error stream of the script, use this class.

Tasks

Executing the Unix Script

Standard Unix Streams

Properties

standardError

The standard error stream.

@property(retain) NSFileHandle *standardError
Discussion

Setting to nil will bind the stream to /dev/null.

The default is nil.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserScriptTask.h

standardInput

The standard input stream.

@property(retain) NSFileHandle *standardInput
Discussion

Setting to nil will bind the stream to /dev/null.

The default is nil.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserScriptTask.h

standardOutput

The standard output stream.

@property(retain) NSFileHandle *standardOutput
Discussion

Setting to nil will bind the stream to /dev/null.

The default is nil.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserScriptTask.h

Instance Methods

executeWithArguments:completionHandler:

Execute the unix script with the specified arguments.

- (void)executeWithArguments:(NSArray *)arguments completionHandler:(NSUserUnixTaskCompletionHandler)handler
Parameters
arguments

An array of NSString objects containing the script arguments. The arguments do not undergo shell expansion, so you do not need to do special quoting, and shell variables are not resolved.

handler

The completion handler Block that returns the result. See NSUserUnixTaskCompletionHandler.

Discussion

This method should be invoked no more than once for a given instance of the class.

If the script completed normally, the completion handler's error parameter will be nil.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserScriptTask.h

Constants

NSUserUnixTaskCompletionHandler

Implement this block to retrieve an error from the Unix scripted executed by executeWithArguments:completionHandler:.

typedef void (^NSUserUnixTaskCompletionHandler)(NSError *error);
Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserScriptTask.h