Files
toolshed-extensions/scripts/init.lua
T

42 lines
1.6 KiB
Lua

-- Scripts: your own small commands (fixes, cleanups, other jobs), each a tool of its own, so it
-- can be found by name ("bluetooth") and given a hotkey. Add one as another tool below; when a
-- theme grows, it can move to an extension of its own.
-- The Magic Keyboard and Trackpad sometimes only work with the cable in, and forgetting and
-- re-pairing them doesn't help. Restarting bluetoothd does, and macOS starts it again within
-- seconds. That takes root, so macOS asks for an administrator password.
local function restart_bluetooth()
local ok, err = pcall(toolshed.exec, {
"/usr/bin/osascript", "-e",
'do shell script "/usr/bin/pkill bluetoothd" with administrator privileges',
})
if ok then return toolshed.t("restarted") end
-- -128 is the password dialog being cancelled, which needs no message.
if tostring(err):find("-128", 1, true) then return nil end
error(toolshed.t("failed", { error = tostring(err) }))
end
return toolshed.toolbox {
key = "scripts",
title = "i18n:toolbox.title",
description = "i18n:toolbox.description",
icon = "terminal",
tint = "orange",
tools = {
{
key = "restart-bluetooth",
title = "i18n:tool.restart-bluetooth.title",
icon = "bluetooth",
keywords = { "bluetooth", "keyboard", "trackpad", "mouse", "fix", "reconnect", "tastatur", "mus", "fiks", "koble til" },
actions = {
{
key = "restart",
title = "i18n:action.restart-bluetooth.restart",
confirm = "i18n:confirm.restart-bluetooth",
run = restart_bluetooth,
},
},
},
},
}