HSVolumeWatcher
TypeA 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
Methods
start() -> HSVolumeWatcher
Starts monitoring volume events.
Declaration
start() -> HSVolumeWatcher
Returns
HSVolumeWatcher
self, for chaining
Example
const w = hs.fs.addVolumeWatcher()
w.setCallback((ev, info) => console.log(ev)).start()
stop() -> HSVolumeWatcher
Stops monitoring volume events.
Declaration
stop() -> HSVolumeWatcher
Returns
HSVolumeWatcher
self, for chaining
Example
w.stop()
setCallback(fn) -> HSVolumeWatcher
Sets the callback function invoked when volume events occur.
Declaration
setCallback(fn) -> HSVolumeWatcher
Parameters
| Name | Type | Description |
|---|---|---|
| fn | function | Called with the event name and an info dictionary; see type documentation for event names and info keys. |
Returns
HSVolumeWatcher
self, for chaining
Example
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.
Declaration
destroy() -> None
Returns
None
Example
w.destroy()