API Docs

A volume event watcher that monitors filesystem mount/unmount/rename events.

Create via hs.fs.addVolumeWatcher(). Set a callback with setCallback(), then call start() to begin receiving events.

The callback receives (event, info):

Event Info keys
"didMount" path: string
"didUnmount" path: string
"willUnmount" path: string
"didRename" path: string, name: string, oldPath?: string, oldName?: string

Example:

const w = hs.fs.addVolumeWatcher()
w.setCallback((event, info) => {
    console.log(event + ": " + info.path)
}).start()

Properties

identifier

string
The unique identifier assigned to this watcher.

Methods

start() -> HSVolumeWatcher

Starts monitoring volume events.
start() -> HSVolumeWatcher
HSVolumeWatcher
self, for chaining
const w = hs.fs.addVolumeWatcher()
w.setCallback((ev, info) => console.log(ev)).start()

stop() -> HSVolumeWatcher

Stops monitoring volume events.
stop() -> HSVolumeWatcher
HSVolumeWatcher
self, for chaining
w.stop()

setCallback(fn) -> HSVolumeWatcher

Sets the callback function invoked when volume events occur.
setCallback(fn) -> HSVolumeWatcher
Name Type Description
fn function Called with the event name and an info dictionary; see type documentation for event names and info keys.
HSVolumeWatcher
self, for chaining
w.setCallback((event, info) => {
    if (event === "didMount") console.log("Mounted: " + info.path)
})

destroy() -> None

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