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 = {
|
applist = {
|
||||||
{shortcut = 'A',appname = 'Launchpad'},
|
{shortcut = 'A',appname = 'Launchpad'},
|
||||||
{shortcut = 'C',appname = 'Google Chrome'},
|
{shortcut = 'C',appname = 'calendar'},
|
||||||
{shortcut = 'D',appname = 'Disk Utility'},
|
{shortcut = 'D',appname = 'Disk Utility'},
|
||||||
{shortcut = 'E',appname = 'Finder'},
|
{shortcut = 'E',appname = 'Finder'},
|
||||||
|
{shortcut = 'G',appname = 'Google Chrome'},
|
||||||
{shortcut = 'Q',appname = 'Activity Monitor'},
|
{shortcut = 'Q',appname = 'Activity Monitor'},
|
||||||
{shortcut = 'T',appname = 'Terminal'},
|
{shortcut = 'T',appname = 'Terminal'},
|
||||||
{shortcut = 'S',appname = 'System Preferences'},
|
{shortcut = 'S',appname = 'System Preferences'},
|
||||||
|
@ -35,25 +35,41 @@ function init()
|
|||||||
hs.pasteboard.setContents(mac)
|
hs.pasteboard.setContents(mac)
|
||||||
end
|
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, {
|
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',
|
tooltip = 'Show Activity Monitor',
|
||||||
fn = function()
|
fn = function()
|
||||||
bindActivityMonitorKey()
|
bindActivityMonitorKey()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
table.insert(menuData, {
|
table.insert(menuData, {
|
||||||
title = 'Disk Utility',
|
title = '打开:磁盘工具 (⇧⌃D)',
|
||||||
tooltip = 'Show Disk Utility',
|
tooltip = 'Show Disk Utility',
|
||||||
fn = function()
|
fn = function()
|
||||||
bindDiskKey()
|
bindDiskKey()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
table.insert(menuData, {
|
||||||
obj.last_down = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $7}\'')
|
title = '打开:系统日历 (⇧⌃C)',
|
||||||
obj.last_up = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $10}\'')
|
tooltip = 'Show calendar',
|
||||||
|
fn = function()
|
||||||
|
bindCalendarKey()
|
||||||
end
|
end
|
||||||
|
})
|
||||||
menubaritem:setMenu(menuData)
|
menubaritem:setMenu(menuData)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,6 +77,10 @@ function scan()
|
|||||||
if interface then
|
if interface then
|
||||||
obj.current_down = hs.execute('netstat -ibn | grep -e ' .. interface .. ' -m 1 | awk \'{print $7}\'')
|
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}\'')
|
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.cpu_used = getCpu()
|
||||||
obj.disk_used = getRootVolumes()
|
obj.disk_used = getRootVolumes()
|
||||||
@ -109,7 +129,6 @@ function scan()
|
|||||||
canvas:delete()
|
canvas:delete()
|
||||||
canvas = nil
|
canvas = nil
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function format_speed(bytes)
|
function format_speed(bytes)
|
||||||
-- 单位 Byte/s
|
-- 单位 Byte/s
|
||||||
@ -128,24 +147,6 @@ function format_speed(bytes)
|
|||||||
end
|
end
|
||||||
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()
|
function getCpu()
|
||||||
local data = hs.host.cpuUsage()
|
local data = hs.host.cpuUsage()
|
||||||
local cpu = (data["overall"]["active"])
|
local cpu = (data["overall"]["active"])
|
||||||
@ -200,46 +201,26 @@ function formatPercent(percent)
|
|||||||
end
|
end
|
||||||
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()
|
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("设置状态栏:系统信息")
|
print("设置状态栏:系统信息")
|
||||||
menuBarItem= hs.menubar.new()
|
menuBarItem= hs.menubar.new()
|
||||||
|
elseif (menuBarItem:isInMenuBar() == false) then
|
||||||
-- menuBarItem:setTitle("")
|
menuBarItem:delete()
|
||||||
-- menuBarItem:setIcon("~/.hammerspoon/icon/caffeine-on.pdf")
|
menuBarItem= hs.menubar.new()
|
||||||
-- queryCpu()
|
end
|
||||||
init()
|
init()
|
||||||
scan()
|
scan()
|
||||||
if obj.timer then
|
if obj.timer then
|
||||||
obj.timer:stop()
|
obj.timer:stop()
|
||||||
obj.timer = nil
|
obj.timer = nil
|
||||||
end
|
end
|
||||||
-- 第三个参数表示当发生异常情况时,定时器是否继续执行下去
|
-- 三秒刷新一次
|
||||||
obj.timer = hs.timer.doEvery(3, scan):start()
|
obj.timer = hs.timer.doEvery(3, scan):start()
|
||||||
|
|
||||||
-- else
|
|
||||||
-- hs.caffeinate.set("displayIdle", false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -247,8 +228,7 @@ end
|
|||||||
function initData()
|
function initData()
|
||||||
setSysInfo()
|
setSysInfo()
|
||||||
--监听系统信息开关的状态,判断是否要重置
|
--监听系统信息开关的状态,判断是否要重置
|
||||||
hs.timer.doEvery(1, resetSysInfoMeun)
|
hs.timer.doEvery(1, setSysInfo)
|
||||||
-- showAllVolumes()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 初始化
|
-- 初始化
|
||||||
@ -262,3 +242,7 @@ end
|
|||||||
function bindDiskKey()
|
function bindDiskKey()
|
||||||
hs.eventtap.keyStroke({ "ctrl", "shift"}, "D")
|
hs.eventtap.keyStroke({ "ctrl", "shift"}, "D")
|
||||||
end
|
end
|
||||||
|
-- 按下添加快捷键时映射到日历快捷键
|
||||||
|
function bindCalendarKey()
|
||||||
|
hs.eventtap.keyStroke({ "ctrl", "shift"}, "C")
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user