docs » EjectMenu

A much-needed eject menu for your Mac menu bar. Allows ejecting individual or all non-internal disks. Ejection can also be triggered on sleep, on lid close, or using a hotkey.

Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/EjectMenu.spoon.zip

API Overview

API Documentation

Variables

eject_on_lid_close
Signature EjectMenu.eject_on_lid_close
Type Variable
Description

Boolean, whether to eject volumes when the laptop lid is closed with an external display connected. There is no "lid close" event, so we detect when the internal display gets disabled. This method is somewhat unreliable (e.g. it also triggers when the internal display goes to sleep due to inactivity), so its default value is false

eject_on_sleep
Signature EjectMenu.eject_on_sleep
Type Variable
Description

Boolean, whether to eject volumes before the system goes to sleep. Default value: true

logger
Signature EjectMenu.logger
Type Variable
Description

Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.

never_eject
Signature EjectMenu.never_eject
Type Variable
Description

List containing volume paths that should never be ejected. Default value: empty list

notify
Signature EjectMenu.notify
Type Variable
Description

Boolean, whether to produce a notification about the volumes that get ejected. Default value: false

other_eject_events
Signature EjectMenu.other_eject_events
Type Variable
Description

List of additional system events on which the volumes should be ejected. The values must be http://www.hammerspoon.org/docs/hs.caffeinate.watcher.html constant values. Default value: empty list

show_in_menubar
Signature EjectMenu.show_in_menubar
Type Variable
Description

Boolean, whether to show a menubar button to eject all drives. Default value: true

Methods

bindHotkeys
Signature EjectMenu:bindHotkeys(mapping)
Type Method
Description

Binds hotkeys for EjectMenu

Parameters:

  • mapping - A table containing hotkey objifier/key details for the following items:
    • ejectAll - eject all volumes.
ejectVolumes
Signature EjectMenu:ejectVolumes()
Type Method
Description

Eject all volumes

Parameters

  • persistent_notifs: a boolean indicating whether notifications (if shown) should be persistent.
shouldEject
Signature EjectMenu:shouldEject(path, info)
Type Method
Description

Determine if a volume should be ejected.

Parameters:

  • path - the mount path of the volume.
  • info - a table containing a data structure as returned by hs.fs.volume.allVolumes(). Returns:
  • A boolean indicating whether the volume should be ejected.
start
Signature EjectMenu:start()
Type Method
Description

Start the watchers for power events and screen changes, to trigger volume ejection.

stop
Signature EjectMenu:stop()
Type Method
Description

Stop the watchers

volumesToEject
Signature EjectMenu:volumesToEject()
Type Method
Description

Return table of volumes to be ejected when "Eject All" is invoked.

Returns:

  • A table in the same format as returned by hs.fs.volume.allVolumes() but containing only those volumes for which EjectMenu:shouldEject() returns true.
  • An integer indicating how many volumes are in the table.