v0.1.6
1、新增系统日历快捷键,更换打开chrome的快捷键 2、优化状态栏信息显示逻辑,防止断网异常 3、系统信息状态栏显示日期,并且能快速获取日期时间,格式:YYYY-MM-DD hh:mm:ss
This commit is contained in:
parent
b476f72140
commit
419b09e2ce
@ -9,9 +9,10 @@ grid.setMargins({0, 0})
|
||||
|
||||
applist = {
|
||||
{shortcut = 'A',appname = 'Launchpad'},
|
||||
{shortcut = 'C',appname = 'Google Chrome'},
|
||||
{shortcut = 'C',appname = 'calendar'},
|
||||
{shortcut = 'D',appname = 'Disk Utility'},
|
||||
{shortcut = 'E',appname = 'Finder'},
|
||||
{shortcut = 'G',appname = 'Google Chrome'},
|
||||
{shortcut = 'Q',appname = 'Activity Monitor'},
|
||||
{shortcut = 'T',appname = 'Terminal'},
|
||||
{shortcut = 'S',appname = 'System Preferences'},
|
||||
|
@ -35,25 +35,41 @@ function init()
|
||||
hs.pasteboard.setContents(mac)
|
||||
end
|
||||
})
|
||||
obj.last_down = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $7}\'')
|
||||
obj.last_up = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $10}\'')
|
||||
else
|
||||
obj.last_down = 0
|
||||
obj.last_down = 0
|
||||
end
|
||||
local date=os.date("%Y-%m-%d %a");
|
||||
table.insert(menuData, {
|
||||
title = 'Activity Monitor',
|
||||
title = 'Date: '..date,
|
||||
tooltip = 'Copy Now DateTime',
|
||||
fn = function()
|
||||
hs.pasteboard.setContents(os.date("%Y-%m-%d %H:%M:%S"))
|
||||
end
|
||||
})
|
||||
table.insert(menuData, {
|
||||
title = '打开:监 视 器 (⇧⌃A)',
|
||||
tooltip = 'Show Activity Monitor',
|
||||
fn = function()
|
||||
bindActivityMonitorKey()
|
||||
end
|
||||
})
|
||||
table.insert(menuData, {
|
||||
title = 'Disk Utility',
|
||||
title = '打开:磁盘工具 (⇧⌃D)',
|
||||
tooltip = 'Show Disk Utility',
|
||||
fn = function()
|
||||
bindDiskKey()
|
||||
end
|
||||
})
|
||||
|
||||
obj.last_down = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $7}\'')
|
||||
obj.last_up = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $10}\'')
|
||||
table.insert(menuData, {
|
||||
title = '打开:系统日历 (⇧⌃C)',
|
||||
tooltip = 'Show calendar',
|
||||
fn = function()
|
||||
bindCalendarKey()
|
||||
end
|
||||
|
||||
})
|
||||
menubaritem:setMenu(menuData)
|
||||
end
|
||||
|
||||
@ -61,6 +77,10 @@ function scan()
|
||||
if interface then
|
||||
obj.current_down = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $7}\'')
|
||||
obj.current_up = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $10}\'')
|
||||
else
|
||||
obj.current_down = 0
|
||||
obj.current_up = 0
|
||||
end
|
||||
|
||||
obj.cpu_used = getCpu()
|
||||
obj.disk_used = getRootVolumes()
|
||||
@ -109,7 +129,6 @@ function scan()
|
||||
canvas:delete()
|
||||
canvas = nil
|
||||
end
|
||||
end
|
||||
|
||||
function format_speed(bytes)
|
||||
-- 单位 Byte/s
|
||||
@ -128,24 +147,6 @@ function format_speed(bytes)
|
||||
end
|
||||
end
|
||||
|
||||
-- function showAllVolumes()
|
||||
-- local vols = hs.fs.volume.allVolumes()
|
||||
-- local msg = "volumes: \n"
|
||||
-- for key, vol in pairs(vols) do
|
||||
-- local size = vol.NSURLVolumeTotalCapacityKey
|
||||
-- local free = vol.NSURLVolumeAvailableCapacityKey
|
||||
-- msg = msg .. key .. 1-free/size.."\n"
|
||||
-- end
|
||||
-- return hs.alert(
|
||||
-- msg,
|
||||
-- {
|
||||
-- ["textSize"] = 12
|
||||
-- },
|
||||
-- hs.screen.mainScreen(),
|
||||
-- 12
|
||||
-- )
|
||||
-- end
|
||||
|
||||
function getCpu()
|
||||
local data = hs.host.cpuUsage()
|
||||
local cpu = (data["overall"]["active"])
|
||||
@ -200,46 +201,26 @@ function formatPercent(percent)
|
||||
end
|
||||
end
|
||||
|
||||
function resetSysInfoMeun()
|
||||
if(config ~=nil and config[1].showSysInfo == 'on' and menuBarItem:isInMenuBar() == false) then
|
||||
menuBarItem:delete()
|
||||
menuBarItem= hs.menubar.new()
|
||||
-- menuBarItem:setTitle("")
|
||||
-- menuBarItem:setIcon("~/.hammerspoon/icon/caffeine-on.pdf")
|
||||
--hs.caffeinate.set("displayIdle", true)
|
||||
-- queryCpu()
|
||||
init()
|
||||
scan()
|
||||
if obj.timer then
|
||||
obj.timer:stop()
|
||||
obj.timer = nil
|
||||
end
|
||||
-- 第三个参数表示当发生异常情况时,定时器是否继续执行下去
|
||||
obj.timer = hs.timer.doEvery(3, scan):start()
|
||||
else
|
||||
menuBarItem:delete()
|
||||
end
|
||||
end
|
||||
|
||||
local setSysInfo= function()
|
||||
if config ~=nil and config[1].showSysInfo == 'on' and menuBarItem == nil then
|
||||
if config ~=nil and config[1].showSysInfo == 'on' then
|
||||
if(menuBarItem ~= nil and menuBarItem:isInMenuBar() == false) then
|
||||
return
|
||||
end
|
||||
if (menuBarItem == nil) then
|
||||
print("设置状态栏:系统信息")
|
||||
menuBarItem= hs.menubar.new()
|
||||
|
||||
-- menuBarItem:setTitle("")
|
||||
-- menuBarItem:setIcon("~/.hammerspoon/icon/caffeine-on.pdf")
|
||||
-- queryCpu()
|
||||
elseif (menuBarItem:isInMenuBar() == false) then
|
||||
menuBarItem:delete()
|
||||
menuBarItem= hs.menubar.new()
|
||||
end
|
||||
init()
|
||||
scan()
|
||||
if obj.timer then
|
||||
obj.timer:stop()
|
||||
obj.timer = nil
|
||||
end
|
||||
-- 第三个参数表示当发生异常情况时,定时器是否继续执行下去
|
||||
-- 三秒刷新一次
|
||||
obj.timer = hs.timer.doEvery(3, scan):start()
|
||||
|
||||
-- else
|
||||
-- hs.caffeinate.set("displayIdle", false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -247,8 +228,7 @@ end
|
||||
function initData()
|
||||
setSysInfo()
|
||||
--监听系统信息开关的状态,判断是否要重置
|
||||
hs.timer.doEvery(1, resetSysInfoMeun)
|
||||
-- showAllVolumes()
|
||||
hs.timer.doEvery(1, setSysInfo)
|
||||
end
|
||||
|
||||
-- 初始化
|
||||
@ -262,3 +242,7 @@ end
|
||||
function bindDiskKey()
|
||||
hs.eventtap.keyStroke({ "ctrl", "shift"}, "D")
|
||||
end
|
||||
-- 按下添加快捷键时映射到日历快捷键
|
||||
function bindCalendarKey()
|
||||
hs.eventtap.keyStroke({ "ctrl", "shift"}, "C")
|
||||
end
|
Loading…
Reference in New Issue
Block a user