Toggle Screen Lock Macos

Open toggle-screen-lock in Script Kit

// Name: Toggle Screen Lock
// Description: Toggle screen lock on macos (never or 2 minutes)
// Author: ElTacitos
import "@johnlindquist/kit"
let password = await arg({
placeholder: "Enter sudo password",
secret: true
})
const resp = await exec(`echo ${password} | sudo -S pmset -g | grep displaysleep`)
const currentSleep = resp.stdout.trimStart().trimEnd().replace( /\s\s+/g, ' ' ).split(/\s/)[1]
const user = (await exec(`whoami`)).stdout
if (currentSleep === "0") {
await exec(`echo ${password} | sudo -S pmset -a displaysleep 2`)
await exec(`defaults write /Users/${user}/Library/Preferences/ByHost/com.apple.screensaver idleTime -int 60`)
await notify("Enabled screen lock")
} else {
await exec(`echo ${password} | sudo -S pmset -a displaysleep 0`)
await exec(`defaults write /Users/${user}/Library/Preferences/ByHost/com.apple.screensaver idleTime -int 0`)
await notify("Disabled screen lock")
}