-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Lua.diagnostics.globals": [ | ||
"hyper", | ||
"hs" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
-- HYPER | ||
-- | ||
-- Hyper is a hyper shortcut modal. | ||
-- | ||
-- Feel free to modify... I use karabiner-elements.app on my laptop and QMK on | ||
-- my mech keyboards to bind a single key to `F19`, which fires all this | ||
-- Hammerspoon-powered OSX automation. | ||
-- | ||
-- I chiefly use it to launch applications quickly from a single press, | ||
-- although I also use it to create "universal" local bindings inspired by | ||
-- Shawn Blanc's OopsieThings. | ||
-- https://thesweetsetup.com/oopsiethings-applescript-for-things-on-mac/ | ||
|
||
local hyper = hs.hotkey.modal.new({}, nil) | ||
|
||
local hyper_toggle = false | ||
|
||
hyper.pressed = function() | ||
hyper_toggle = false | ||
hyper:enter() | ||
hs.timer.delayed.new(0.5, function () | ||
hyper_toggle = true | ||
end):start() | ||
end | ||
hyper.released = function() | ||
if not hyper_toggle then | ||
hs.eventtap.keyStrokes(" ") | ||
-- hs.eventtap.keyStroke({}, 'space') | ||
end | ||
hyper:exit() | ||
end | ||
|
||
hyper.launchOrHide = function(app_config) | ||
hyper_toggle = true | ||
local app = hs.application.get(app_config.bundleID) | ||
if app:isFrontmost() and #app:visibleWindows() > 0 then | ||
app:hide() | ||
elseif app:isRunning() then | ||
hs.application.launchOrFocusByBundleID(app_config.bundleID) | ||
end | ||
end | ||
|
||
-- Expects a configuration table with an applications key that has the | ||
-- following form: | ||
-- config_table.applications = { | ||
-- ['com.culturedcode.ThingsMac'] = { | ||
-- bundleID = 'com.culturedcode.ThingsMac', | ||
-- hyper_key = 't', | ||
-- tags = {'planning', 'review'}, | ||
-- local_bindings = {',', '.'} | ||
-- }, | ||
-- } | ||
hyper.start = function(config_table) | ||
-- Set the key you want to be HYPER to F19 in karabiner or keyboard | ||
-- Bind the Hyper key to the hammerspoon modal | ||
hs.hotkey.bind({}, config_table.hyper_key, hyper.pressed, hyper.released) | ||
-- Use the hyper key with the application config to use the `hyper_key` | ||
hs.fnutils.map(config_table.applications, function(app) | ||
-- Apps that I want to jump to | ||
if app.hyper_key then | ||
hyper:bind({}, app.hyper_key, function() hyper.launchOrHide(app); end) | ||
end | ||
|
||
-- I use hyper to power some shortcuts in different apps If the app is closed | ||
-- and I press the shortcut, open the app and send the shortcut, otherwise | ||
-- just send the shortcut. | ||
-- if app.local_bindings then | ||
-- hs.fnutils.map(app.local_bindings, function(key) | ||
-- hyper:bind({}, key, nil, function() | ||
-- if hs.application.get(app.bundleID) then | ||
-- hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key) | ||
-- else | ||
-- hyper.launch(app) | ||
-- hs.timer.waitWhile( | ||
-- function() | ||
-- return not hs.application.get(app.bundleID):isFrontmost() | ||
-- end, | ||
-- function() | ||
-- hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key) | ||
-- end | ||
-- ) | ||
-- end | ||
-- end) | ||
-- end) | ||
-- end | ||
end) | ||
end | ||
|
||
hyper.bindKey = function(x, key_modifiers, key, to_modifiers, to) | ||
hs.alert.show(#key_modifiers) | ||
hs.alert.show(key) | ||
hyper:bind(key_modifiers or {}, key, function() | ||
hyper_toggle = true | ||
hs.eventtap.keyStroke(to_modifiers or {}, to) | ||
end) | ||
end | ||
|
||
return hyper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
config = {} | ||
config.applications = { | ||
['com.runningwithcrayons.Alfred'] = { | ||
bundleID = 'com.runningwithcrayons.Alfred', | ||
local_bindings = {'c', 'space', 'o'} | ||
}, | ||
['PathFinder'] = { | ||
bundleID = 'com.cocoatech.PathFinder', | ||
hyper_key = 'f' | ||
}, | ||
['com.culturedcode.ThingsMac'] = { | ||
bundleID = 'com.culturedcode.ThingsMac', | ||
hyper_key = 't', | ||
tags = {'planning', 'review', 'tasks'}, | ||
whitelisted = true, | ||
local_bindings = {',', '.'}, | ||
rules = { | ||
{nil, 1, hs.layout.maximized} | ||
} | ||
}, | ||
['com.toggl.toggldesktop.TogglDesktop'] = { | ||
bundleID = 'com.toggl.toggldesktop.TogglDesktop', | ||
local_bindings = {'p'} | ||
}, | ||
['com.ideasoncanvas.mindnode.macos'] = { | ||
bundleID = 'com.ideasoncanvas.mindnode.macos', | ||
tags = {'research'}, | ||
hyper_key = 'u', | ||
rules = { | ||
{nil, 1, hs.layout.maximized} | ||
} | ||
}, | ||
['com.apple.MobileSMS'] = { | ||
bundleID = 'com.apple.MobileSMS', | ||
hyper_key = 'q', | ||
tags = {'communication', 'distraction'}, | ||
rules = { | ||
{nil, 2, hs.layout.right30} | ||
} | ||
}, | ||
["微信"] = { | ||
bundleID = 'com.tencent.xinWeChat', | ||
hyper_key = 'w' | ||
}, | ||
["Wechat"] = { | ||
bundleID = 'com.tencent.xinWeChat', | ||
hyper_key = 'w' | ||
}, | ||
["QQ"] = { | ||
bundleID = 'com.tencent.qq', | ||
hyper_key = 'z' | ||
}, | ||
["qq"] = { | ||
bundleID = 'com.tencent.qq', | ||
hyper_key = 'z' | ||
}, | ||
["mqq"] = { | ||
bundleID = 'com.tencent.mqq', | ||
hyper_key = 'z' | ||
}, | ||
["DingTalk"] = { | ||
bundleID = 'com.alibaba.DingTalkMac', | ||
}, | ||
["Telegram"] = { | ||
bundleID = 'com.tdesktop.Telegram', | ||
} | ||
} | ||
|
||
config.domains = { | ||
['twitter.com'] = { | ||
url = 'twitter.com', | ||
tags = {'distraction', 'socialmedia'} | ||
}, | ||
['instagram.com'] = { | ||
url = 'instagram.com', | ||
tags = {'distraction', 'socialmedia'} | ||
}, | ||
['reddit.com'] = { | ||
url = 'reddit.com', | ||
tags = {'distraction'} | ||
}, | ||
['instapaper.com'] = { | ||
url = 'instapaper.com', | ||
tags = {'distraction', 'reading'} | ||
}, | ||
['youtube.com'] = { | ||
url = 'youtube.com', | ||
tags = {'distraction'} | ||
} | ||
} | ||
|
||
-- configure spaces for headspace | ||
config.spaces = {} | ||
config.funcs = {} | ||
-- config.projects = hs.settings.get("secrets").toggl.projects | ||
-- config.hyper_key = 'space' | ||
|
||
-- hyper = require('hyper') | ||
-- hyper.start(config) | ||
|
||
-- 方向键 | ||
-- hyper:bindKey({}) | ||
-- hyper:bindKey({}, 'i', {}, 'up') | ||
-- hyper:bindKey({}, 'k', {}, 'down') | ||
|
||
hs.urlevent.bind('launchOrHide', function (eventName, params) | ||
local app_bundle_id = config.applications[params["name"]].bundleID | ||
local app = hs.application.get(app_bundle_id) | ||
|
||
if not app then | ||
hs.application.open(app_bundle_id) | ||
elseif app:isFrontmost() and #app:visibleWindows() > 0 then | ||
app:hide() | ||
if not app:isHidden() then | ||
for _, window in pairs(app:allWindows()) do | ||
window:close() | ||
end | ||
end | ||
else | ||
hs.application.launchOrFocusByBundleID(app:bundleID()) | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{:templates {:launch "osascript -e 'tell application \"Alfred 4\" to run trigger \"launch%s\" in workflow \"yqrashawn.workflow.launcher\" with argument \"\"'" | ||
:alf "open /Applications/Alfred\\ 4.app && osascript -e 'tell application \"Alfred 4\" to run trigger \"%s\" in workflow \"%s\"'" | ||
:km "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"%s\"'" | ||
:kma "osascript -e 'tell application \"Keyboard Maestro Engine\" to do script \"Activate%s\"'" | ||
:open "open \"%s\"" | ||
:opena "open -a \"%s\"" | ||
:show "osascript -e 'set appName to \"%s\"\nset startIt to false\ntell application \"System Events\"\n if not (exists process appName) then\n set startIt to true\n else\n set frontmost of process appName to true\n end if\nend tell\nif startIt then\n tell application appName to activate\nend if'\n" | ||
:toggle "osascript -e 'set appName to \"%s\"\nset startIt to false\ntell application \"System Events\"\n if not (exists process appName) then\n set startIt to true\n else if frontmost of process appName then\n set visible of process appName to false\n else\n set frontmost of process appName to true\n end if\nend tell\nif startIt then\n tell application appName to activate\nend if'" | ||
:type "osascript -e 'tell application \"System Events\" to keystroke \"%s\" as text'" | ||
;; :focus "/usr/local/bin/yabai -m display --focus \"%s\" & /usr/local/bin/yabai -m space --focus \"%s\"" | ||
:hs "open -g hammerspoon://%s" | ||
:hsa "open -g hammerspoon://launchOrHide?name=%s"} | ||
:main | ||
[{:des "Space_Fn" | ||
:rules [[:##spacebar ["fn-mode" 1] nil {:afterup ["fn-mode" 0] | ||
:alone :spacebar}] | ||
; delete | ||
[:delete_or_backspace :delete_forward :fn-mode] | ||
|
||
; 方向键 | ||
[:!Ti [:up_arrow :up_arrow :up_arrow :up_arrow :up_arrow] :fn-mode] | ||
[:!Tk [:down_arrow :down_arrow :down_arrow :down_arrow :down_arrow] :fn-mode] | ||
[:##i :up_arrow :fn-mode] | ||
[:##k :down_arrow :fn-mode] | ||
[:##j :left_arrow :fn-mode] | ||
[:##l :right_arrow :fn-mode] | ||
|
||
; 切换输入法 | ||
[:tab :!Cspacebar :fn-mode] | ||
; 打开App | ||
;; [:w :!TCw :fn-mode] | ||
[:w [:hsa Wechat] :fn-mode] | ||
[:z [:hsa mqq] :fn-mode] | ||
[:t [:hsa Telegram] :fn-mode] | ||
[:e [:hsa DingTalk] :fn-mode] | ||
[:f [:hsa PathFinder] :fn-mode] | ||
|
||
; Window Manage | ||
;; [:1 :!Tup_arrow :fn-mode] | ||
;; [:2 :!Tdown_arrow :fn-mode] | ||
|
||
; Media Control | ||
[:n :play_or_pause :fn-mode] | ||
[:m :mute :fn-mode] | ||
[:comma :rewind :fn-mode] | ||
[:period :fastforward :fn-mode] | ||
[:up_arrow :volume_increment :fn-mode] | ||
[:down_arrow :volume_decrement :fn-mode] | ||
|
||
; 数字 -> F区 | ||
[:1 :f1 :fn-mode] | ||
[:2 :f2 :fn-mode] | ||
[:3 :f3 :fn-mode] | ||
[:4 :f4 :fn-mode] | ||
[:5 :f5 :fn-mode] | ||
[:6 :f6 :fn-mode] | ||
[:7 :f7 :fn-mode] | ||
[:8 :f8 :fn-mode] | ||
[:9 :f9 :fn-mode] | ||
[:0 :f10 :fn-mode] | ||
[:hyphen :f11 :fn-mode] | ||
[:equal_sign :f12 :fn-mode]]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters