diff options
-rwxr-xr-x | bin/st-doy1.local/power-usage | 10 | ||||
-rw-r--r-- | hammerspoon/init.lua | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/bin/st-doy1.local/power-usage b/bin/st-doy1.local/power-usage new file mode 100755 index 0000000..46d61db --- /dev/null +++ b/bin/st-doy1.local/power-usage @@ -0,0 +1,10 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; + +my $power_data = `system_profiler SPPowerDataType`; +my ($volts) = $power_data =~ /Voltage.*: (.*)/; +my ($amps) = $power_data =~ /Amperage.*: (.*)/; + +printf "%0.2f\n", $volts * $amps / 1000000; diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index f72699d..2f6b836 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -134,14 +134,20 @@ end) enter_bindings(hs.application.frontmostApplication():name()) current_application_watcher:start() -menubar = hs.menubar.new() +cpu_usage_bar = hs.menubar.new() timer = hs.timer.doEvery(1, function() hs.host.cpuUsage(function(cpu) local cpuUsage = cpu["overall"]["active"] - menubar:setTitle(math.floor(cpuUsage + 0.5) .. "%") + cpu_usage_bar:setTitle(math.floor(cpuUsage + 0.5) .. "%") end) end) +power_usage_bar = hs.menubar.new() +timer = hs.timer.doEvery(5, function() + local watts = hs.execute("/Users/doy/.bin/st-doy1.local/power-usage") + power_usage_bar:setTitle(string.gsub(watts, "\n", "") .. "W") +end) + hs.caffeinate.set("systemIdle", true, true) hs.alert("Hammerspoon config reloaded") |