
Control 🔨 Hammerspoon directly from Raycast.
✅ Requirements
~/.hammerspoon/init.lua. If you don't have this file, you can create it by running touch ~/.hammerspoon/init.lua in your terminal.hs.allowAppleScript(true), save the file and reload Hammerspoon.The List Scripts command allows you to list and run custom Hammerspoon scripts directly from Raycast.
To set it up, you first need to define a lua global variable in your Hammerspoon configuration file, this variable should be a table that contains two functions, list and execute. These two functions are going to be called by this raycast extension when listing and running scripts:
list function should return a json array describing your scripts. each item in the array can have the following properties:
id: a unique identifier for the script (must be unique, it is used to run scripts) (required).name: the name of the script to be displayed in Raycast (required).description: a short description of the script to be displayed in Raycast.keywords: an array of keywords to help with searching for the script in Raycast.execute function expects to receive a script id as an argument, and execute the corresponding script.Finally, you need to put the name of the global variable you created in your Hammerspoon configuration file in the List Scripts command preferences.
Example of a Hammerspoon configuration file with the List Scripts setup:
-- <<rest of your configuration file>>
local scriptDefs = {
{ id = 'test', name = 'Test', description = 'This is a test script' },
{ id = 'test2', name = 'Test 2', description = 'This is another test script' }
}
local scriptActions = {
test = function ()
hs.alert.show('Test script executed')
end,
test2 = function ()
hs.alert.show('Test 2 script executed')
end
}
__SCRIPTS__ = {
list = function ()
return hs.json.encode(scriptDefs)
end,
execute = function (id)
local scriptAction = scriptActions[id]
if not scriptAction then
error('User Script with id "' .. id .. '" not found')
end
scriptAction()
end
}
Open the Hammerspoon configuration file
Reloads the Hammerspoon configuration file
Opens the Hammerspoon Console window and focuses it
Displays the Hammerspoon Preferences panel and focuses it
Displays the Hammerspoon documentation panel and focuses it
Search Hammerspoon Documentation
List and quickly trigger User Defined Hammerspoon Scripts
Quits and restarts Hammerspoon
Shows the version of Hammerspoon
Clears the Hammerspoon Console
List Scripts command to trigger user defined hammerspoon scripts.Clear Console preference to Reload Configuration File command to optionally clear the Hammerspoon Console before reloadingOpen Configuration File command to open the Hammerspoon configuration file (the application used to open the file is configurable).Search Documentation command to allow for quick searching of Hammerspoon documentation.