-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropdown
executable file
·51 lines (40 loc) · 1.31 KB
/
dropdown
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
#!/usr/bin/env python3
"""
App dropdown script for Yabai
It'll display or hide provided app by name
LICENSE: GPLv3+ by [email protected]
"""
import json
import subprocess
import click
from click import echo
YABAI = '/usr/local/bin/yabai'
def run(cmd: str):
return subprocess.run(cmd, shell=True, capture_output=True).stdout
def run_json(cmd: str):
return json.loads(run(cmd))
@click.command()
@click.argument('app')
@click.option('--scratchpad', '-s', default='6', show_default=True,
help='hidden workspace name')
def main(app, scratchpad):
"""Dropdown functionality for yabai. Either summon or hide program by app name"""
echo(f'calling {app}')
windows = run_json(f'{YABAI} -m query --windows')
for window in windows:
if window['app'] == app:
break
else:
echo(f'app "{app}" not found', err=True)
exit(1)
if window['visible']:
# if visible, hide it to scratchpad workspace
run(f'{YABAI} -m window {window["id"]} --space {scratchpad}')
echo(f'{app} hidden')
else:
# otherwise pull to current workspace and focus
run(f'{YABAI} -m window {window["id"]} --space mouse && '
f'{YABAI} -m window --focus {window["id"]}')
echo(f'{app} revealed')
if __name__ == '__main__':
main()