Skip to content

A Hammerspoon Spoon that opens/closes apps or runs an arbitrary function when a USB device is connected/disconnected.

Notifications You must be signed in to change notification settings

malob/USBDeviceActions.spoon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

USBDeviceActions.spoon

A Hammerspoon Spoon that opens/closes apps or runs an arbitrary function when a USB device is connected/disconnected.

Example configuration (using SpoonInstall.spoon):

function toggleKeyboardLayout(x)
  if x then
    hs.keycodes.setLayout("U.S.")
  else
    hs.keycodes.setLayout("Colemak")
  end
end

spoonInstall:andUse(
  "USBDeviceActions",
  {
    config = {
      devices = {
        ScanSnapiX500EE            = { apps = { "ScanSnap Manager Evernote Edition" } },
        Planck                     = { fn = toggleKeyboardLayout },
        ["Corne Keyboard (crkbd)"] = { fn = toggleKeyboardLayout }
      }
    },
    start = true
  }
)

The keys of devices should correspond to productNames of USB devices. You can find the productName for a connected USB device using hs.usb.attachedDevices()).

The value of the apps key should contain a list of apps that will be launched/killed when the USB device is connected/disconnected. The value of the fn key should be a single parameter function that will be passed true/false when the USB device is connected/disconnected.

About

A Hammerspoon Spoon that opens/closes apps or runs an arbitrary function when a USB device is connected/disconnected.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages