hammerspoon2-docs
    Preparing search index...

    Function open

    • Open a file, returning an HSFile object for reading and/or writing it.

      Mode Read Write Creates Truncates Notes
      "r" ✓ The default
      "r+" ✓ ✓
      "w" ✓ ✓ ✓
      "w+" ✓ ✓ ✓ ✓
      "a" ✓ ✓ Every write goes to the end of the file
      "a+" ✓ ✓ ✓ Reads start at the beginning; every write goes to the end
      Add x to a w mode ("wx", "w+x") to fail if the file already exists. A b is accepted and
      ignored, since all files can be read as text or bytes.
      Directories cannot be opened. A file that can't be opened (for example because it doesn't exist) is
      not logged to the Console, since that is often an expected outcome; check hs.fs.lastError instead.
      Invalid arguments, such as an unknown mode, are logged.
      Close the file with close() when you are finished with it; any files still open are closed
      automatically when your configuration is reloaded.

      Parameters

      • path: string

        Path to the file. ~ is expanded.

      • Optionalmode: string

        The open mode. Defaults to "r".

      • Optionalpermissions: number

        POSIX permission bits applied if the file is created, e.g. 0o600 (0 creates a file with no permissions). Defaults to 0o644 when omitted; any other non-integer value, including NaN, fails with EINVAL. The process umask is applied in either case.

      Returns HSFile | null

      An HSFile, or null on failure (see hs.fs.lastError).