docs » HeadphoneAutoPause

Play/pause music players when headphones are connected/disconnected

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

API Overview

API Documentation

Variables

autoResume
Signature HeadphoneAutoPause.autoResume
Type Variable
Description

Boolean value indicating if music should be automatically resumed when headphones are plugged in again. Only works if music was automatically paused when headphones were unplugged.

Notes
  • Default value: true
Source Source/HeadphoneAutoPause.spoon/init.lua line 43
control
Signature HeadphoneAutoPause.control
Type Variable
Description

Table containing one key per application, with the value indicating whether HeadphoneAutoPause should try to pause/unpause that application in response to the headphone being plugged/unplugged.

Notes
  • The key name must ideally correspond to the name of the corresponding hs.* module. Default value:
{
   itunes = true,
   spotify = true,
   deezer = true,
   vox = false -- Vox has built-in headphone detection support
}
Source Source/HeadphoneAutoPause.spoon/init.lua line 22
controlfns
Signature HeadphoneAutoPause.controlfns
Type Variable
Description

Table containing control functions for each application to control.

Notes
  • The keys must correspond to the values in HeadphoneAutoPause.control, and the value is a table with the following elements:
  • appname - application name (case-sensitive, as the application appears to the system)
  • isPlaying - function that returns a true value if the application is playing
  • play - function that starts playback in the application
  • pause - function that pauses playback in the application
  • The default value includes definitions for iTunes, Spotify, Deezer and Vox, using the corresponding functions from hs.itunes, hs.spotify, hs.deezer and hs.vox, respectively.
Source Source/HeadphoneAutoPause.spoon/init.lua line 68
logger
Signature HeadphoneAutoPause.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/HeadphoneAutoPause.spoon/init.lua line 17

Methods

audiodevwatch
Signature HeadphoneAutoPause:audiodevwatch(dev_uid, event_name)
Type Method
Description

Callback function to use as an audio device watcher, to pause/unpause the application on headphones plugged/unplugged

Parameters
  • dev_uid - The audio device
  • event_name - The event name
Returns
Source Source/HeadphoneAutoPause.spoon/init.lua line 97
defaultControlFns
Signature HeadphoneAutoPause.defaultControlFns(app)
Type Method
Description

Generate the most common set of application control definition.

Parameters
  • app - name of the application, with its correct letter casing (i.e. "iTunes"). The name as provided will be used to find the running application, and its lowercase version will be used to find the corresponding hs.* module.
Returns
  • A table in the correct format for HeadphoneAutoPause.controlfns, using the lower-case value of app as the module name (for example, if app = "iTunes", the module loaded will be hs.itunes, and assuming the functions isPlaying(), play() and pause() exist in that module.
Source Source/HeadphoneAutoPause.spoon/init.lua line 51
start
Signature HeadphoneAutoPause:start()
Type Method
Description

Start headphone detection on all audio devices that support it

Parameters
  • None
Returns
Source Source/HeadphoneAutoPause.spoon/init.lua line 137
stop
Signature HeadphoneAutoPause:stop()
Type Method
Description

Stop headphone detection

Parameters
  • None
Returns
Source Source/HeadphoneAutoPause.spoon/init.lua line 157