API Docs

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

Example:

const w = hs.fs.createPathWatcher("/Users/me/Documents")
w.setCallback((paths, flags) => {
    paths.forEach((p, i) => console.log(flags[i].join(",") + ": " + p))
}).start()

Properties

identifier

string
The unique identifier assigned to this watcher.

Methods

start() -> HSPathWatcher

Starts monitoring the watched path for filesystem changes.
start() -> HSPathWatcher
HSPathWatcher
self, for chaining
const w = hs.fs.createPathWatcher("/tmp")
w.setCallback((paths, flags) => console.log(paths.join(", "))).start()

stop() -> HSPathWatcher

Stops monitoring the watched path.
stop() -> HSPathWatcher
HSPathWatcher
self, for chaining
w.stop()

setCallback(fn) -> HSPathWatcher

Sets the callback invoked when filesystem changes are detected.
setCallback(fn) -> HSPathWatcher
Name Type Description
fn function Called with an array of changed paths and a parallel array of per-path flag string arrays.
HSPathWatcher
self, for chaining
w.setCallback((paths, flags) => {
    paths.forEach((p, i) => console.log(p + ": " + flags[i].join(", ")))
})

destroy() -> None

Stops the watcher and releases all resources. Called automatically during shutdown.
destroy() -> None
None
w.destroy()