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.
Notes
  • 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
Source Source/EjectMenu.spoon/init.lua line 48
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
Source Source/EjectMenu.spoon/init.lua line 43
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.
Source Source/EjectMenu.spoon/init.lua line 28
never_eject
Signature EjectMenu.never_eject
Type Variable
Description List containing volume paths that should never be ejected. Default value: empty list
Source Source/EjectMenu.spoon/init.lua line 33
notify
Signature EjectMenu.notify
Type Variable
Description Boolean, whether to produce a notification about the volumes that get ejected. Default value: `false`
Source Source/EjectMenu.spoon/init.lua line 38
other_eject_events
Signature EjectMenu.other_eject_events
Type Variable
Description List of additional system events on which the volumes should be ejected.
Notes
Source Source/EjectMenu.spoon/init.lua line 62
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
Source Source/EjectMenu.spoon/init.lua line 57

Methods

bindHotkeys
Signature EjectMenu:bindHotkeys(mapping, ejectAll)
Type Method
Description Binds hotkeys for EjectMenu
Parameters
  • mapping - A table containing hotkey objifier/key details for the following items:
  • ejectAll - eject all volumes.
Returns
Source Source/EjectMenu.spoon/init.lua line 215
ejectVolumes
Signature EjectMenu:ejectVolumes()
Type Method
Description Eject all volumes
Parameters
  • persistent_notifs: a boolean indicating whether notifications (if shown) should be persistent.
Returns
Source Source/EjectMenu.spoon/init.lua line 123
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.
Source Source/EjectMenu.spoon/init.lua line 70
start
Signature EjectMenu:start()
Type Method
Description Start the watchers for power events and screen changes, to trigger volume ejection.
Parameters
  • None
Returns
Source Source/EjectMenu.spoon/init.lua line 241
stop
Signature EjectMenu:stop()
Type Method
Description Stop the watchers
Parameters
  • None
Returns
Source Source/EjectMenu.spoon/init.lua line 283
volumesToEject
Signature EjectMenu:volumesToEject()
Type Method
Description Return table of volumes to be ejected when "Eject All" is invoked.
Parameters
  • None
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.
Source Source/EjectMenu.spoon/init.lua line 85