Skip to content

Instantly share code, notes, and snippets.

@rhyswynne
Created March 1, 2020 16:00
Show Gist options
  • Save rhyswynne/b4927b53636d873fa975a72511abfe83 to your computer and use it in GitHub Desktop.
Save rhyswynne/b4927b53636d873fa975a72511abfe83 to your computer and use it in GitHub Desktop.
Lua script that will update a death counter or file by 1
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
-- This opens the file and reads the file into a variable (t)
local deathcounterfile = assert(io.open("[full path to the text file you created]", "r"))
local deathcount = deathcounterfile:read("*all")
-- This adds 1 to the value of deathcount and closes the file
deathcount = deathcount + 1
deathcounterfile:close()
-- We reopen the same file but in write mode. We write the death count to the file and save & closes it.
local newfile = assert(io.open("[full path to the text file you created]", "w"))
io.output(newfile)
io.write(deathcount)
newfile:close()
-- This you don't need, but it prints the deathcount to the console
print(deathcount)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment