Systemator class reference

NSObject
Systemator.h
Systemator.m

Overview

Implements common system related stuff that can be used in all application classes.

Note that this class only contains class methods, so no instance is needed.

Tasks

Tasks and processes handling

XML helpers

File system helpers

Exception helpers

Systemator(ClassPrivateAPI)

Class methods

runTask:

Runs the given task.

+ (void)runTask:(NSString *) command
Parameters
command

The command line of the task.

Exceptions
NSException

Thrown if running the task fails.

Discussion

This is a helper method which facilitates running external commands. It creates a task, parameterizes it and runs it. After the tasks ends, the method will also return. The command automatically detects user's default shell and takes path from it.

Note that the method accepts variable number of arguments following the command. The list must end with nil otherwise SIGSEGV error will be raised.

See also
Declared in
Systemator.h

runShellTaskWithCommand:

Runs the given command with the user's shell.

+ (void)runShellTaskWithCommand:(NSString *) command
Parameters
command

The command to execute.

Exceptions
NSException

Thrown if running task fails.

Discussion

This will first get the user's default shell and will use it to execute the given command. The given command will first be saved to the temporary path then it will be executed and temporary file removed. This command allows the clients to properly handle shell path.

See also
Declared in
Systemator.h

applyXSLTFromFile:toDocument:error:

Applies the XSLT from the given file to the document and returns the resulting object.

+ (id)applyXSLTFromFile:(NSString *) filename toDocument:(NSXMLDocument *) document error:(NSError **) error
Parameters
filename

The name of the XSLT file including full path.

document

The NSXMLDocument to transform.

error

If transformation failed, error is reported here.

Return value

Returns transformed object or nil if transformation failed.

Discussion

This will first load the XSLT from the given file and will apply it to the document. It will return the transformed object which is either an NSXMLDocument if transformation created an XML or NSData otherwise. If transformation failed, nil is returned and error description is passed over the error parameter.

This message internally sends + applyXSLTFromFile:toDocument:arguments:error: with arguments set to nil.

See also
Declared in
Systemator.h

applyXSLTFromFile:toDocument:arguments:error:

Applies the XSLT from the given file to the document and returns the resulting object.

+ (id)applyXSLTFromFile:(NSString *) filename toDocument:(NSXMLDocument *) document arguments:(NSDictionary *) arguments error:(NSError **) error
Parameters
filename

The name of the XSLT file including full path.

document

The NSXMLDocument to transform.

arguments

An NSDictionary containing all arguments to be passed to the XSLT. May be nil if no argument is to be passed.

error

If transformation failed, error is reported here.

Return value

Returns transformed object or nil if transformation failed.

Discussion

This will first load the XSLT from the given file and will apply it to the document. It will return the transformed object which is either an NSXMLDocument if transformation created an XML or NSData otherwise. If transformation failed, nil is returned and error description is passed over the error parameter.

See also
Declared in
Systemator.h

createDirectory:

Creates the given directory.

+ (void)createDirectory:(NSString *) path
Parameters
path

The directory path to create.

Exceptions
NSException

Thrown if creation fails.

Discussion

If the directory (or file with that name) already exists, nothing happens. Otherwise the directory is created. If creation fails, exception is thrown.

Declared in
Systemator.h

copyItemAtPath:toPath:

Copies the given file or directory to the given destination.

+ (void)copyItemAtPath:(NSString *) source toPath:(NSString *) destination
Parameters
source

The source of the copy.

destination

The destination to copy to.

Exceptions
NSException

Thrown if copying fails.

Discussion

If the destination already exists, it is removed first.

See also
Declared in
Systemator.h

removeItemAtPath:

Removes the given file or directory (including contents).

+ (void)removeItemAtPath:(NSString *) path
Parameters
path

The path to remove.

Exceptions
NSException

Thrown if removing fails.

Discussion

If the path exists, it is removed, otherwise nothing happens. If removing fails, exception is raised.

Declared in
Systemator.h

linesFromContentsOfFile:

Reads the contents of the given file and returns the array of all lines.

+ (NSMutableArray *)linesFromContentsOfFile:(NSString *) filename
Parameters
filename

The name of the file including full path.

Exceptions
NSException

Thrown if reading from the file fails.

Return value

Returns the array of NSString instanced representing individual file lines.

Discussion

The file is assumed to be in NSASCIIStringEncoding. If reading fails, the exception explaining the reason is thrown. To write the array of strings into the filename, you can use + writeLines:toFile:.

Declared in
Systemator.h

writeLines:toFile:

Writes the given array of strings to the given file.

+ (void)writeLines:(NSArray *) lines toFile:(NSString *) filename
Parameters
lines

The NSArray containing strings to write.

filename

The name of the file.

Exceptions
NSException

Thrown if writting fails.

Discussion

If the file already exists, it is truncated before writting. If writting fails, the exception explaining the reason is thrown. To read the contents of a file into the array of lines, you can use + linesFromContentsOfFile:.

Declared in
Systemator.h

readPropertyListFromFile:

Reads the property list from the given filename.

+ (id)readPropertyListFromFile:(NSString *) filename
Parameters
filename

The name of the plist file.

Exceptions
NSException

Thrown if reading fails.

Return value

Returns the object that represents the property list data or nil if not possible.

Discussion

If the file doesn't exist or reading fails, exception is thrown.

See also
Declared in
Systemator.h

writePropertyList:toFile:

Writes the given property list to the given filename.

+ (void)writePropertyList:(id) plist toFile:(NSString *) filename
Parameters
plist

The property list object to be serialized.

filename

The name of the file to write to.

Exceptions
NSException

Thrown if writting fails.

Discussion

If writting fails, exception is thrown.

See also
Declared in
Systemator.h

throwExceptionWithName:basedOnError:

Throws an NSException with description from the given NSError;.

+ (void)throwExceptionWithName:(NSString *) name basedOnError:(NSError *) error
Parameters
name

The exception name.

error

The NSError which description and data to use for exception.

Exceptions
NSException

Always thrown...

Discussion

See also + throwExceptionWithName:withDescription:.

Declared in
Systemator.h

throwExceptionWithName:withDescription:

Throws an NSException with the given description.

+ (void)throwExceptionWithName:(NSString *) name withDescription:(NSString *) description
Parameters
name

The exception name.

description

The description of the error.

Exceptions
NSException

Always thrown...

Discussion

See also + throwExceptionWithName:basedOnError:.

Declared in
Systemator.h

systemShellPath

Determines the system's shell path.

+ (NSString *)systemShellPath
Exceptions
NSException

Thrown if shell path cannot be determined.

Return value

Returns the shell path.

Discussion

This method will first determine the kind of shell that is used by the user. Then it will get the path from the shell.

Declared in
Systemator.m

linesFromString:

Returns the array of all lines from the given string.

+ (NSMutableArray *)linesFromString:(NSString *) string
Parameters
string

The string to get the lines from.

Return value

Returns the array containing strings representing all lines from the string.

Declared in
Systemator.m

© 2008-2009 Tomaz Kragelj. All rights reserved. (Last updated: 2009-08-24)
Back to index / hierarchy.