-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_batch_gui.py
65 lines (48 loc) · 1.51 KB
/
make_batch_gui.py
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
import os
import subprocess
current_dir = os.getcwd()
mdet_bat_contents = '''
@echo on
(
cd {}
conda activate pwlife
python mdet_gui.py
conda deactivate
pause
)
'''.format(current_dir)
ano_bat_contents = '''
@echo on
(
cd {}
cd anotate
python anotateform_soft.py
pause
)
'''.format(current_dir)
# ファイルを書き込みモードで開く
with open('detect_gui.bat', 'w') as file:
file.write(mdet_bat_contents)
with open('anotation_form.bat', 'w') as file:
file.write(ano_bat_contents)
def create_shortcuts_in_directory(directory,bat_name):
desktop = os.path.join(os.environ['USERPROFILE'], 'Desktop')
shortcut_path = os.path.join(desktop, bat_name + ".lnk")
target_path = os.path.join(directory, bat_name + ".bat")
vbs_script = f"""
Set WshShell = WScript.CreateObject("WScript.Shell")
Set Shortcut = WshShell.CreateShortcut("{shortcut_path}")
Shortcut.TargetPath = "{target_path}"
Shortcut.WorkingDirectory = "{os.path.dirname(target_path)}"
Shortcut.WindowStyle = 1
Shortcut.IconLocation = "{target_path}, 0"
Shortcut.Save
"""
with open("create_shortcut.vbs", "w") as file:
file.write(vbs_script)
subprocess.run(['cscript', '//nologo', 'create_shortcut.vbs'])
os.remove("create_shortcut.vbs")
if __name__ == "__main__":
create_shortcuts_in_directory(current_dir,"detect_gui")
create_shortcuts_in_directory(current_dir,"anotation_form")
print("Shortcuts created successfully on the desktop.")