Compare commits
No commits in common. "2f948e13fb7642827c98047fd54e093afa4be274" and "6d7e11c2386e9d9b579fe0c8bbac582493cf97de" have entirely different histories.
2f948e13fb
...
6d7e11c238
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@
|
|||||||
/*.zip
|
/*.zip
|
||||||
.idea/
|
.idea/
|
||||||
build/
|
build/
|
||||||
.DS_Store
|
|
17
init.lua
17
init.lua
@ -3,15 +3,14 @@ package.path = hs.configdir .. '/?.lua;' .. hs.configdir .. '/?/init.lua;' .. hs
|
|||||||
|
|
||||||
require "modules/reload"
|
require "modules/reload"
|
||||||
require "modules/hotkey"
|
require "modules/hotkey"
|
||||||
-- require "modules/commons"
|
require "modules/commons"
|
||||||
-- require "modules/system"
|
require "modules/system"
|
||||||
require "modules/windows"
|
require "modules/windows"
|
||||||
require "modules/launcher"
|
require "modules/launcher"
|
||||||
-- require "modules/systemInfo"
|
require "modules/systemInfo"
|
||||||
-- require "modules/snippet"
|
require "modules/snippet"
|
||||||
-- require "modules/timesync"
|
require "modules/timesync"
|
||||||
-- require "modules/caffeine"
|
require "modules/caffeine"
|
||||||
-- require "modules/inputstat"
|
require "modules/inputstat"
|
||||||
require "modules/dict"
|
require "modules/dict"
|
||||||
-- require "modules/jsonFormat"
|
require "modules/jsonFormat"
|
||||||
|
|
@ -1,40 +0,0 @@
|
|||||||
var args = $.NSProcessInfo.processInfo.arguments;
|
|
||||||
var argv = [];
|
|
||||||
var argc = args.count;
|
|
||||||
for (var i = 4; i < argc; i++) {
|
|
||||||
argv.push(ObjC.unwrap(args.objectAtIndex(i)));
|
|
||||||
}
|
|
||||||
var inputUrl = argv[0];
|
|
||||||
|
|
||||||
var Chrome = Application('Google Chrome');
|
|
||||||
var windows = Chrome.windows();
|
|
||||||
var foundTab = false;
|
|
||||||
|
|
||||||
// 遍历所有窗口和标签页
|
|
||||||
for (var i = 0; i < windows.length; i++) {
|
|
||||||
var window = windows[i];
|
|
||||||
var tabs = window.tabs();
|
|
||||||
for (var j = 0; j < tabs.length; j++) {
|
|
||||||
var tab = tabs[j];
|
|
||||||
if (tab.url().startsWith(inputUrl)) {
|
|
||||||
// 激活包含URL的窗口
|
|
||||||
Chrome.activate();
|
|
||||||
window.index = i + 1; // 窗口索引是从1开始的
|
|
||||||
// 激活对应的标签页
|
|
||||||
window.activeTabIndex = j + 1; // 标签索引也是从1开始的
|
|
||||||
foundTab = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (foundTab) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有找到匹配的标签页,打开新窗口并导航到URL
|
|
||||||
if (!foundTab) {
|
|
||||||
var newWindow = Chrome.Window().make();
|
|
||||||
var newTab = newWindow.tabs[0];
|
|
||||||
newTab.url = inputUrl;
|
|
||||||
Chrome.activate();
|
|
||||||
}
|
|
@ -3,4 +3,3 @@ hyperShift = {"alt", "shift"}
|
|||||||
hyperCtrl = {"alt", "ctrl"}
|
hyperCtrl = {"alt", "ctrl"}
|
||||||
hyperAlt = {"ctrl", "alt", "shift"}
|
hyperAlt = {"ctrl", "alt", "shift"}
|
||||||
hyperCmd = {"alt", "cmd"}
|
hyperCmd = {"alt", "cmd"}
|
||||||
f19 = {'cmd','alt','shift','ctrl'}
|
|
@ -1,58 +1,46 @@
|
|||||||
-- http://qtdebug.com/mac-hammerspoon/
|
local hotkey = require "hs.hotkey"
|
||||||
-- 键和应用对
|
local grid = require "hs.grid"
|
||||||
-- 提示: 数字作为键,需要使用 [Number] 的格式
|
local window = require "hs.window"
|
||||||
|
local application = require "hs.application"
|
||||||
|
local appfinder = require "hs.appfinder"
|
||||||
|
local fnutils = require "hs.fnutils"
|
||||||
|
|
||||||
local KEY_APP_PAIRS = {
|
grid.setMargins({0, 0})
|
||||||
[5] = "QSpace Pro.app",
|
|
||||||
Q = "QQ.app",W = "WeChat.app",E = "Microsoft Edge.app",T = "iTerm.app",I = "IINA.app",O = "Obsidian.app", P = "/Users/tanpengsccd/Applications/JetBrains Toolbox/PyCharm Professional Edition.app",
|
|
||||||
A = "ILink.app", S = "Surge.app",F = "/System/Volumes/Data/Applications/Apifox.app" ,G = "https://ai.h6.work",K = "Spotify.app", L = "NeteaseMusic.app",
|
|
||||||
Z = "QSpace Pro.app",X = "Xcode.app",C = "Google Chrome.app",V = "Visual Studio Code.app",B="iTerm.app",N = "Notes.app",M = "Telegram.app", -- B = "wechatwebdevtools.app"*/
|
|
||||||
|
|
||||||
-- [2] = "Notable.app",
|
applist = {
|
||||||
-- [3] = "Typora.app",
|
{shortcut = 'A',appname = 'Launchpad'},
|
||||||
|
{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'},
|
||||||
|
{shortcut = 'Z',appname = 'Calculator'},
|
||||||
}
|
}
|
||||||
-- 修饰键 这里设置为 f19
|
|
||||||
|
|
||||||
local MOFIFER_KEY = f19
|
fnutils.each(applist, function(entry)
|
||||||
-- local MOFIFER_KEY = "alt"
|
hotkey.bind({'ctrl', 'shift'}, entry.shortcut, entry.appname, function()
|
||||||
|
application.launchOrFocus(entry.appname)
|
||||||
-- 显示 Finder:
|
-- toggle_application(applist[i].appname)
|
||||||
hs.hotkey.bind(MOFIFER_KEY, "1", function()
|
end)
|
||||||
hs.application.open("/System/Library/CoreServices/Finder.app")
|
|
||||||
hs.application.get("com.apple.finder"):setFrontmost(true)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- 重新加载配置
|
-- Toggle an application between being the frontmost app, and being hidden
|
||||||
hs.hotkey.bind(f19, "R", function()
|
function toggle_application(_app)
|
||||||
hs.reload()
|
local app = appfinder.appFromName(_app)
|
||||||
end)
|
if not app then
|
||||||
--------------------------------------------------------------------------------------
|
application.launchOrFocus(_app)
|
||||||
-- 按下 "F19+键" 会打开或激活对应的应用,如果应用不是绝对路径,则指的是 /Applications 中的应用 --
|
return
|
||||||
--------------------------------------------------------------------------------------
|
end
|
||||||
function bindAppWithHotkey(keyAppPairs,modifierKey)
|
local mainwin = app:mainWindow()
|
||||||
-- hs.alert.show("modifierKey,key: " .. modifierKey .. "," .. keyAppPairs ..)
|
if mainwin then
|
||||||
-- 确保MODIFIER_KEY已经被传递进来或在这里定义,例如MODIFIER_KEY = {"cmd", "alt"}
|
if mainwin == window.focusedWindow() then
|
||||||
for key, target in pairs(keyAppPairs) do
|
mainwin:application():hide()
|
||||||
hs.hotkey.bind(modifierKey, key, function()
|
else
|
||||||
hs.alert.show("" .. target)
|
mainwin:application():activate(true)
|
||||||
-- 如果是以http前缀的,就是网址,需要使用 Chrome 打开
|
mainwin:application():unhide()
|
||||||
if string.find(target, "^http") then -- 使用'^http'来确保字符串以http开始
|
mainwin:focus()
|
||||||
-- hs.alert.show("URL:" .. target)
|
end
|
||||||
local url = target
|
|
||||||
local scriptPath = os.getenv("HOME") .. "/.hammerspoon/jxa/openInChrome.jxa" -- 使用环境变量获取用户目录
|
|
||||||
local command = "osascript -l JavaScript " .. scriptPath .. " '" .. url .. "'"
|
|
||||||
hs.execute(command)
|
|
||||||
return
|
|
||||||
elseif string.find(target, "app$") then -- 其它都当APP 处理
|
|
||||||
-- hs.alert.show("APP:" .. target)
|
|
||||||
hs.application.launchOrFocus(target) -- 这种可以只传入app name,也可以传入路径
|
|
||||||
return
|
|
||||||
else
|
|
||||||
hs.alert.show("未知类型:" .. target)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 这里绑定
|
|
||||||
bindAppWithHotkey(KEY_APP_PAIRS,MOFIFER_KEY)
|
|
@ -11,12 +11,11 @@ local fnutils = require "hs.fnutils"
|
|||||||
local geometry = require "hs.geometry"
|
local geometry = require "hs.geometry"
|
||||||
local mouse = require "hs.mouse"
|
local mouse = require "hs.mouse"
|
||||||
|
|
||||||
local MOFIFER_KEY_HALF = f19
|
|
||||||
-- default 0.2
|
-- default 0.2
|
||||||
window.animationDuration = 0.1
|
window.animationDuration = 0
|
||||||
|
|
||||||
-- left half
|
-- left half
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "Left", function()
|
hotkey.bind(hyper, "Left", function()
|
||||||
if window.focusedWindow() then
|
if window.focusedWindow() then
|
||||||
window.focusedWindow():moveToUnit(layout.left50)
|
window.focusedWindow():moveToUnit(layout.left50)
|
||||||
else
|
else
|
||||||
@ -25,37 +24,37 @@ hotkey.bind(MOFIFER_KEY_HALF, "Left", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- right half
|
-- right half
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "Right", function()
|
hotkey.bind(hyper, "Right", function()
|
||||||
window.focusedWindow():moveToUnit(layout.right50)
|
window.focusedWindow():moveToUnit(layout.right50)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- top half
|
-- top half
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "Up", function()
|
hotkey.bind(hyper, "Up", function()
|
||||||
window.focusedWindow():moveToUnit'[0,0,100,50]'
|
window.focusedWindow():moveToUnit'[0,0,100,50]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- bottom half
|
-- bottom half
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "Down", function()
|
hotkey.bind(hyper, "Down", function()
|
||||||
window.focusedWindow():moveToUnit'[0,50,100,100]'
|
window.focusedWindow():moveToUnit'[0,50,100,100]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- left top quarter
|
-- left top quarter
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "[", function()
|
hotkey.bind(hyperAlt, "Left", function()
|
||||||
window.focusedWindow():moveToUnit'[0,0,50,50]'
|
window.focusedWindow():moveToUnit'[0,0,50,50]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- right bottom quarter
|
-- right bottom quarter
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "'", function()
|
hotkey.bind(hyperAlt, "Right", function()
|
||||||
window.focusedWindow():moveToUnit'[50,50,100,100]'
|
window.focusedWindow():moveToUnit'[50,50,100,100]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- right top quarter
|
-- right top quarter
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, "]", function()
|
hotkey.bind(hyperAlt, "Up", function()
|
||||||
window.focusedWindow():moveToUnit'[50,0,100,50]'
|
window.focusedWindow():moveToUnit'[50,0,100,50]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- left bottom quarter
|
-- left bottom quarter
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, ";", function()
|
hotkey.bind(hyperAlt, "Down", function()
|
||||||
window.focusedWindow():moveToUnit'[0,50,50,100]'
|
window.focusedWindow():moveToUnit'[0,50,50,100]'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ hotkey.bind(hyper, 'C', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- maximize window
|
-- maximize window
|
||||||
hotkey.bind(MOFIFER_KEY_HALF, 'return', function() window.focusedWindow(): maximize() end)
|
hotkey.bind(hyper, 'M', function() toggle_maximize() end)
|
||||||
|
|
||||||
-- defines for window maximize toggler
|
-- defines for window maximize toggler
|
||||||
local frameCache = {}
|
local frameCache = {}
|
||||||
@ -87,23 +86,34 @@ function toggle_maximize()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- display a keyboard hint for switching focus to each window
|
-- display a keyboard hint for switching focus to each window
|
||||||
-- hotkey.bind(hyperShift, '/', function()
|
hotkey.bind(hyperShift, '/', function()
|
||||||
-- hints.windowHints()
|
hints.windowHints()
|
||||||
-- -- Display current application window
|
-- Display current application window
|
||||||
-- -- hints.windowHints(hs.window.focusedWindow():application():allWindows())
|
-- hints.windowHints(hs.window.focusedWindow():application():allWindows())
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- switch active window
|
-- switch active window
|
||||||
-- hotkey.bind(hyperShift, "H", function()
|
hotkey.bind(hyperShift, "H", function()
|
||||||
-- window.switcher.nextWindow()
|
window.switcher.nextWindow()
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
|
-- move active window to previous monitor
|
||||||
|
hotkey.bind(hyperShift, "Left", function()
|
||||||
|
window.focusedWindow():moveOneScreenWest()
|
||||||
|
end)
|
||||||
|
|
||||||
-- move cursor to previous/next monitor
|
-- move active window to next monitor
|
||||||
-- hotkey.bind(hyperCtrl, "Right", function ()
|
hotkey.bind(hyperShift, "Right", function()
|
||||||
-- focusScreen(window.focusedWindow():screen():previous())
|
window.focusedWindow():moveOneScreenEast()
|
||||||
-- end)
|
end)
|
||||||
hotkey.bind(f19, "`", function ()
|
|
||||||
|
-- move cursor to previous monitor
|
||||||
|
hotkey.bind(hyperCtrl, "Right", function ()
|
||||||
|
focusScreen(window.focusedWindow():screen():previous())
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- move cursor to next monitor
|
||||||
|
hotkey.bind(hyperCtrl, "Left", function ()
|
||||||
focusScreen(window.focusedWindow():screen():next())
|
focusScreen(window.focusedWindow():screen():next())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -143,37 +153,19 @@ moveto = function(win, n)
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- cycled move active window to another screen
|
|
||||||
hs.hotkey.bind( f19, 'tab', function()
|
-- move cursor to monitor 1 and maximize the window
|
||||||
-- get the focused window
|
hotkey.bind(hyperShift, "1", function()
|
||||||
local win = hs.window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
-- get the screen where the focused window is displayed, a.k.a. current screen
|
moveto(win, 1)
|
||||||
local screen = win:screen()
|
|
||||||
-- compute the unitRect of the focused window relative to the current screen
|
|
||||||
-- and move the window to the next screen setting the same unitRect
|
|
||||||
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- -- move active window to monitor 1 and maximize the window
|
hotkey.bind(hyperShift, "2", function()
|
||||||
-- hotkey.bind(f19, "1", function()
|
local win = window.focusedWindow()
|
||||||
-- local win = window.focusedWindow()
|
moveto(win, 2)
|
||||||
-- moveto(win, 1)
|
end)
|
||||||
-- end)
|
|
||||||
|
|
||||||
-- hotkey.bind(f19, "2", function()
|
hotkey.bind(hyperShift, "3", function()
|
||||||
-- local win = window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
-- moveto(win, 2)
|
moveto(win, 3)
|
||||||
-- end)
|
end)
|
||||||
|
|
||||||
-- hotkey.bind(f19, "3", function()
|
|
||||||
-- local win = window.focusedWindow()
|
|
||||||
-- moveto(win, 3)
|
|
||||||
-- end)
|
|
||||||
|
|
||||||
-- -- move active window to previous/next monitor
|
|
||||||
-- hotkey.bind(MOFIFER_KEY_HALF, '-', function()
|
|
||||||
-- window.focusedWindow():moveOneScreenWest():maximize()
|
|
||||||
-- end)
|
|
||||||
-- hotkey.bind(MOFIFER_KEY_HALF, '=', function()
|
|
||||||
-- window.focusedWindow():moveOneScreenEast():maximize()
|
|
||||||
-- end)
|
|
0
timesync/timesync.sh
Normal file → Executable file
0
timesync/timesync.sh
Normal file → Executable file
Loading…
Reference in New Issue
Block a user