Opt

public enum Opt

A customization option for a Caffeination.

Note

Any given Caffeination can be passed only one of each Opt. So, for instance, it is valid to pass a .timed and .process Opt; however, it is not possible to have two different .process Opts.
  • Prevents disk idle sleep.

    Declaration

    Swift

    case disk
  • Prevents display sleep.

    Declaration

    Swift

    case display
  • Prevents system idle sleep.

    Declaration

    Swift

    case idle
  • Prevents system sleep.

    Note

    On MacBooks, will only work when connected to AC power.

    Declaration

    Swift

    case system
  • Simulates user activity to keep display awake.

    Note

    caffeinate should automatically timeout after 5 seconds if .timed is not also selected. However, due to a bug in the caffeinate tool, this does not currently happen, and the process will continue indefinitely.

    Declaration

    Swift

    case user
  • Terminates Caffeination when process with specified PID exits. Might be preempted by .timed.

    Declaration

    Swift

    case process(Int32)
  • Terminates Caffeination after specified period of time in seconds. Might be preempted by .process.

    Declaration

    Swift

    case timed(TimeInterval)
  • The default options for a standard Caffeination.

    Declaration

    Swift

    public static var defaults: [Opt] { get }
  • Converts an Opt to the raw argument(s) passed to caffeinate.

    Declaration

    Swift

    public var argumentList: [String] { get }
  • Returns an Opt corresponding to a single caffeinate argument string.

    Note

    Options that require a numerical argument (e.g., -t) should use from(_ array:).

    Declaration

    Swift

    public static func from(_ string: String) -> Opt?

    Parameters

    string

    The String containing the argument to parse.

    Return Value

    An Opt corresponding to the argument passed, or nil if the argument was not recognized.

  • Returns an Opt from a [String] containing a single argument to caffeinate and, if necessary, an associated numerical argument.

    Note

    nil will be returned if:
    • an unknown argument is passed (e.g., ["-f"]).
    • a value is passed for an argument that doesn’t accept one (e.g., ["-m", "42"]).
    • no value is passed for an argument that requires one (e.g., ["-w"]).
    • multiple option arguments are passed (e.g., ["-d", "-m"]) (use array(from:) instead).

    Declaration

    Swift

    public static func from(_ array: [String]) -> Opt?

    Parameters

    array

    The array containing the single argument to caffeinate and an associated value (if necessary).

    Return Value

    An Opt corresponding to the argument, or nil.

  • Returns an [Opt] from a [String] containing raw arguments (and their associated integer values, if needed) to caffeinate, or nil if an invalid value is passed (see discussion).

    Note

    nil will be returned if:
    • an unknown argument is passed (e.g., ["-f"]).
    • a value is passed for an argument that doesn’t accept one (e.g., ["-m", "42"]).
    • no value is passed for an argument that requires one (e.g., ["-w", "-d"]).

    Declaration

    Swift

    public static func array(from stringArray: [String]) -> [Opt]?

    Parameters

    stringArray

    The array from which to parse the argument (and associated value).

    Return Value

    An array of Opts corresponding to the values passed, or nil.