Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add Anykey hotkeys.
- Loading branch information
Showing
6 changed files
with
81 additions
and
2 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
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
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
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
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,19 @@ | ||
{ | ||
"hotkeys": | ||
[ { "title": "Launch iTerm 2" | ||
, "key": "`" | ||
, "modifiers": ["⌥", "⇧"] | ||
, "shellCommand": "open /Applications/iTerm.app" | ||
} | ||
, { "title": "Launch Music" | ||
, "key": "F8" | ||
, "modifiers": ["fn", "⌃"] | ||
, "shellCommand": "open /System/Applications/Music.app" | ||
} | ||
, { "title": "Launch Process" | ||
, "key": "space" | ||
, "modifiers": ["⌥", "⇧"] | ||
, "shellCommand": "osascript -e 'tell application \"Alfred 4\" to search \"proc\"'" | ||
} | ||
] | ||
} |
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,42 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'json' | ||
require 'shellwords' | ||
|
||
SCRIPTS_DIR = File.join(__dir__, '..', 'applescript') | ||
SCRIPT_TRIGGER = | ||
<<~APPLESCRIPT | ||
tell application id "com.runningwithcrayons.Alfred" to run trigger "script" in workflow "com.temochka.alfred.process" with argument "%<arg>s" | ||
APPLESCRIPT | ||
|
||
script_hotkeys = Dir.glob(File.join(SCRIPTS_DIR, '*', 'launcher.json')).flat_map do |launcher| | ||
JSON.parse(File.read(launcher), symbolize_names: true) | ||
.fetch(:items) | ||
.select { |item| item[:anykey] } | ||
.map do |item| | ||
arg = { | ||
alfredworkflow: item.merge( | ||
variables: item.fetch(:variables, {}).merge( | ||
focusedapp: File.join(File.basename(File.dirname(launcher))) | ||
) | ||
) | ||
} | ||
|
||
item[:anykey] | ||
.merge( | ||
shellCommand: "osascript -e '#{format(SCRIPT_TRIGGER, arg: arg.to_json.gsub(/\"/, "\\\""))}'", | ||
title: item[:anykey].fetch(:title, item[:title]) | ||
) | ||
.merge( | ||
if item[:keyword] | ||
{} | ||
else | ||
{ onlyIn: [File.basename(File.dirname(launcher))] } | ||
end | ||
) | ||
end | ||
end | ||
|
||
base_hotkeys = JSON.parse(File.read(File.join(__dir__, 'Anykey.base.json')), symbolize_names: true).fetch(:hotkeys, []) | ||
|
||
puts JSON.pretty_generate(hotkeys: base_hotkeys + script_hotkeys) |