Module for filesystem operations.
hs.fs provides a comprehensive set of filesystem operations covering file
I/O, directory management, path manipulation, metadata access, symbolic
links, Finder tags, and macOS-specific features like file bookmarks and
Uniform Type Identifiers.
It replaces both Hammerspoon v1's hs.fs module and the functionality that
was previously available through Lua's built-in io and file modules.
// Or let hs.fs.withFile() close it for you: constheader = hs.fs.withFile("~/image.png", "r", f=>f.readBytes(8));
Errors
Functions that fail return null or false and set hs.fs.lastError to an object like
{code: "ENOENT", message: "No such file or directory"}. Most failures are also logged to the
Console; failures that are often expected (such as hs.fs.open() on a missing file) are not.
Module for filesystem operations.
hs.fsprovides a comprehensive set of filesystem operations covering file I/O, directory management, path manipulation, metadata access, symbolic links, Finder tags, and macOS-specific features like file bookmarks and Uniform Type Identifiers. It replaces both Hammerspoon v1'shs.fsmodule and the functionality that was previously available through Lua's built-inioandfilemodules.Reading and writing files
Working with open files
For incremental, positioned, binary, or locked access, open the file to get an
Errors
Functions that fail return
nullorfalseand seths.fs.lastErrorto an object like{code: "ENOENT", message: "No such file or directory"}. Most failures are also logged to the Console; failures that are often expected (such ashs.fs.open()on a missing file) are not.Directory operations
Path utilities
Metadata