HSPathWatcher
TypeWatches 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 pathsflags: 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
Methods
start() -> HSPathWatcher
Starts monitoring the watched path for filesystem changes.
Declaration
start() -> HSPathWatcher
Returns
HSPathWatcher
self, for chaining
Example
const w = hs.fs.createPathWatcher("/tmp")
w.setCallback((paths, flags) => console.log(paths.join(", "))).start()
stop() -> HSPathWatcher
Stops monitoring the watched path.
Declaration
stop() -> HSPathWatcher
Returns
HSPathWatcher
self, for chaining
Example
w.stop()
setCallback(fn) -> HSPathWatcher
Sets the callback invoked when filesystem changes are detected.
Declaration
setCallback(fn) -> HSPathWatcher
Parameters
| Name | Type | Description |
|---|---|---|
| fn | function | Called with an array of changed paths and a parallel array of per-path flag string arrays. |
Returns
HSPathWatcher
self, for chaining
Example
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.
Declaration
destroy() -> None
Returns
None
Example
w.destroy()