Skip to content

Instantly share code, notes, and snippets.

@cmsj
Forked from cabrinha/bar.lua
Created November 12, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmsj/93f525e32828da07e0ef to your computer and use it in GitHub Desktop.
Save cmsj/93f525e32828da07e0ef to your computer and use it in GitHub Desktop.
trying to create a status bar in hammerspoon
-- Trying to make a status bar
-- Internaught 11/11/15
-- Something about the screens ...
-- I guess this draws a border?
-- local boxBorder = 2
-- Lets draw the box, on as many screens as we have, across the top
for _,screen in ipairs(hs.screen.allScreens()) do
local x, y = screen:position()
local frame = screen:frame()
local box = hs.drawing.rectangle(hs.geometry.rect(frame.x, frame.y, frame.w, 25))
box:setFillColor({["red"]=0.1,["blue"]=0.1,["green"]=0.1,["alpha"]=1}):setFill(true):show()
-- Create all the stuff we want displayed
-- iTunes / Now Playing
local artist = hs.itunes.getCurrentArtist()
local album = hs.itunes.getCurrentAlbum()
local track = hs.itunes.getCurrentTrack()
local iTunes = string.format("%s - %s - %s", artist, album, track)
local timer = hs.timer.doEvery(3, function()
text:setText(string.format("%s - %s - %s", artist, album, track))
end)
timer:start()
-- Let's define how the text is displayed
local text = hs.drawing.text(hs.geometry.rect(frame.x + 2, frame.y + 2, frame.w -2, 20), iTunes)
-- Set the text color
text:setTextColor({["red"]=1,["blue"]=1,["green"]=1,["alpha"]=1})
-- Set the font size and font type
text:setTextSize(14)
text:setTextFont('Tamzen7x14')
-- Show it off
text:show()
end
-- timer stopped to prevent repeated notifications of error.
/Users/yuppie/.hammerspoon/bar.lua:22: attempt to index a nil value (global 'text')
stack traceback:
/Users/yuppie/.hammerspoon/bar.lua:22: in function </Users/yuppie/.hammerspoon/bar.lua:21>
stack traceback:
-- timer stopped to prevent repeated notifications of error.
/Users/yuppie/.hammerspoon/bar.lua:22: attempt to index a nil value (global 'text')
stack traceback:
/Users/yuppie/.hammerspoon/bar.lua:22: in function </Users/yuppie/.hammerspoon/bar.lua:21>
stack traceback:
-- timer stopped to prevent repeated notifications of error.
/Users/yuppie/.hammerspoon/bar.lua:22: attempt to index a nil value (global 'text')
stack traceback:
/Users/yuppie/.hammerspoon/bar.lua:22: in function </Users/yuppie/.hammerspoon/bar.lua:21>
stack traceback:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment