-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsm.py
More file actions
130 lines (105 loc) · 3.11 KB
/
sm.py
File metadata and controls
130 lines (105 loc) · 3.11 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
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
123
124
125
126
127
128
129
130
#######
# sm.py ~= session manager
#
# Session manager is a quick way to access and run scripts.
# Simply a easier way to run scripts when not AFK. Mobile manager
# now will act in way to run scripts for laptops and other devices.
#
#######
import keyboard
import subprocess
import os
from os.path import isfile, join
current_folder = ""
index_folder = [""]
folders = {"":[]}
selections = []
options = 0
page = 0
def get_list(path):
# get list of files in the path directory
# onlyfiles = [(i, f, 0) for i, f in enumerate(listdir(path)) if isfile(join(path, f))]
options = []
folder_num = 0
# (location, name, ignore, folder = True)
for i, f in enumerate(os.listdir(path)):
if isfile(join(path, f)):
ignore = f[1] == '-'
options.append((i, f, ignore, False))
elif f != "storage":
options.insert(folder_num, (i, "^" + f, ignore, True))
index_folder.append(f)
folders[f] = get_list(join(path, f))
folder_num += 1
return options
def exec_command(data):
# executes commands
command = "C:\\Users\\danie\\Documents\\AutoInterface\\scripts\\" + data
try:
print("Log: exec => ", command, "...")
# 'shell=True' strongly discouraged because its vulnerable to shell injection
# but since we are using "start cmd /c" 'shell=True' must remain, for now.
subprocess.call("start cmd /c " + command, shell=True)
except:
print("Error: couldn't process " + command)
def show_options(files, page):
global selections
os.system('cls')
print('----------------------\n')
print("Page->", page)
result = ""
selections = []
i = 0
for j, f in enumerate(files):
if f[2] == False and j >= page * 10 and i < 10:
option_num = i % 10
i += 1
result += str(option_num)
selections.append(f)
if f[1][0] != '^':
result += ": " + f[1][:-4] + "\n"
else:
result += ": " + f[1] + "\n"
print(result)
def prevpage():
global options, page
page -= 1
if page < 0: page = 0
show_options(options, page)
def nextpage():
global options, page
page += 1
show_options(options, page)
def push_command(command):
global options, selections, page, current_folder
select = selections[command]
if select[1][0] == '^':
page = 0
options = folders[select[1][1:]]
current_folder = select[1][1:]
show_options(options, page)
else:
exec_command(current_folder + "\\" + select[1])
def home_folder():
global options, page, current_folder
page = 0
options = folders[""]
current_folder = ""
show_options(options, page)
def main():
global options, page
path = "C:\\Users\\danie\\Documents\\AutoInterface\\scripts"
options = get_list(path)
folders[""] = options
show_options(options, page)
print("press option: ")
keyboard.add_hotkey('f', nextpage, suppress=True)
keyboard.add_hotkey('a', prevpage, suppress=True)
keyboard.add_hotkey('b', home_folder, suppress=True)
for i in range(-1, 9):
keyboard.add_hotkey(str(i + 1), push_command, args=[i + 1], suppress=True)
keyboard.wait('esc')
keyboard.unhook_all()
keyboard.unhook_all_hotkeys()
if __name__ == "__main__":
main()