-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapp.py
More file actions
66 lines (52 loc) · 1.35 KB
/
openapp.py
File metadata and controls
66 lines (52 loc) · 1.35 KB
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
#!/usr/bin/env python
# coding:utf-8
import os
import getpass
__version__ = 1.0
__author__ = sherry
app_path = '/Applications'
zsh_path = '~/.zshrc'
# list dir app
def get_dir_list(path):
dir_list = os.listdir(path)
return dir_list
# filter the app list
def filter_list(dir_list):
app_dict = {}
for app in dir_list:
if app.endswith('.app'):
app_dict[app[:-4].replace(" ", "").lower()] = app[:-4]
del dir_list
return app_dict
def generate_command_lines(app_dict):
commands = []
for line in app_dict.keys():
open_command = "\"open /Applications/" + app_dict[line] + ".app\""
alias_command = "alias " + line + "=" + open_command
echo_command = "echo \'" + alias_command + "\' >>~/.zshrc"
os.system(echo_command)
commands.append(echo_command)
return commands
def get_user():
return getpass.getuser()
def get_path(path):
return '/Users/' + get_user() + path
if __name__ == '__main__':
list = filter_list(get_dir_list(app_path))
print generate_command_lines(list)
os.system("source ~/.zshrc")
# print list
# TODO:
'''
# 用click的库
## 加一个openapp 的快捷键: 方便管理所有alias .
# 其中包括: 添加参数, 即可:
1. 删除
2. 添加(?)
3. update
4. 查找(search)
5. 重置
'''
'''
脑洞大开, 做一个GUI
'''