-
Notifications
You must be signed in to change notification settings - Fork 9
/
CreateLauncherModeTemplate.rb
122 lines (104 loc) · 2.62 KB
/
CreateLauncherModeTemplate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby
# You can generate json by executing the following command on Terminal.
#
# $ ruby ./CreateLauncherModeTemplate.json.rb
#
# Parameters
def parameters
{
:simultaneous_threshold_milliseconds => 500,
:trigger_key => 'o',
}
end
############################################################
require 'json'
def main
data = {
'title' => 'O-Launcher',
'rules' => [
{
'description' => 'O-Launcher',
'manipulators' => [
generate_launcher_mode('i', [], [{ 'shell_command' => "open -a 'notion.app'" }]),
generate_launcher_mode('1', [], [{ 'shell_command' => "open -a 'Brave Browser Beta.app'" }]),
generate_launcher_mode('a', [], [{ 'shell_command' => "open -a 'Activity Monitor.app'" }]),
generate_launcher_mode('c', [], [{ 'shell_command' => "open -a 'Visual Studio Code.app'" }]),
generate_launcher_mode('i', [], [{ 'shell_command' => "open -a 'iTerm.app'" }]),
].flatten,
},
],
}
puts JSON.pretty_generate(data)
end
def generate_launcher_mode(from_key_code, mandatory_modifiers, to)
data = []
############################################################
h = {
'type' => 'basic',
'from' => {
'key_code' => from_key_code,
'modifiers' => {
'mandatory' => mandatory_modifiers,
'optional' => [
'any',
],
},
},
'to' => to,
'conditions' => [
{
'type' => 'variable_if',
'name' => 'launcher_mode',
'value' => 1,
},
],
}
data << h
############################################################
h = {
'type' => 'basic',
'from' => {
'simultaneous' => [
{
'key_code' => parameters[:trigger_key],
},
{
'key_code' => from_key_code,
},
],
'simultaneous_options' => {
'key_down_order' => 'strict',
'key_up_order' => 'strict_inverse',
'to_after_key_up' => [
{
'set_variable' => {
'name' => 'launcher_mode',
'value' => 0,
},
},
],
},
'modifiers' => {
'mandatory' => mandatory_modifiers,
'optional' => [
'any',
],
},
},
'to' => [
{
'set_variable' => {
'name' => 'launcher_mode',
'value' => 1,
},
},
].concat(to),
'parameters' => {
'basic.simultaneous_threshold_milliseconds' => parameters[:simultaneous_threshold_milliseconds],
},
}
data << h
############################################################
data
end
main