hammerspoon2-docs
    Preparing search index...

    Class HSPathWatcher

    Watches a filesystem path for changes and invokes a callback when they occur.

    Created via hs.fs.createPathWatcher(path). Set a callback with setCallback(), then call start() to begin receiving events.

    The callback receives (paths, flags):

    • paths: array of changed file/directory paths
    • flags: parallel array of string arrays, one per path, describing what changed

    Possible flag values in each per-path array:

    Flag Meaning
    "itemCreated" Item was created
    "itemRemoved" Item was removed
    "itemRenamed" Item was renamed or moved
    "itemModified" File data was modified
    "itemInodeMetaMod" Inode metadata changed (permissions, timestamps, etc.)
    "itemFinderInfoMod" Finder info changed
    "itemChangeOwner" Ownership or group changed
    "itemXattrMod" Extended attributes changed
    "itemIsFile" The item is a file
    "itemIsDir" The item is a directory
    "itemIsSymlink" The item is a symbolic link
    "itemIsHardlink" The item is a hard link
    "itemIsLastHardlink" This is the last hard link to the inode
    "itemCloned" Item was cloned
    "ownEvent" Event was generated by this process
    "mustScanSubDirs" Subtree must be rescanned (events may have been dropped)
    "userDropped" Events were dropped at the user-space level
    "kernelDropped" Events were dropped at the kernel level
    "rootChanged" The watched root path itself changed
    "mount" A volume was mounted under the watched path
    "unmount" A volume was unmounted from under the watched path
    Index
    identifier: string

    The unique identifier assigned to this watcher.

    • Stops the watcher and releases all resources. Called automatically during shutdown.

      Returns void

    • Sets the callback invoked when filesystem changes are detected.

      Parameters

      • fn: (paths: string[], flags: string[][]) => void

        Called with an array of changed paths and a parallel array of per-path flag string arrays.

      Returns HSPathWatcher

      self, for chaining

    • Starts monitoring the watched path for filesystem changes.

      Returns HSPathWatcher

      self, for chaining

      A started watcher, and its callback, stay alive until it's stopped, even if you don't keep a reference to it