-
Notifications
You must be signed in to change notification settings - Fork 0
/
locate_chrome.py
49 lines (38 loc) · 1.36 KB
/
locate_chrome.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
import platform, os
class PathNotFoundException(Exception):
"""
Raised when the path to local chrome cannot be found.
"""
def get_path_macos():
# ------------------------------ #
# Uses util mdfind to find the path of Chrome
# ------------------------------ #
path = (os.popen("""mdfind \'kMDItemDisplayName == "Google Chrome" && kMDItemKind == Application\'""").read().strip() + "/Contents/MacOS/Google Chrome")
if len(path) == 0:
raise PathNotFoundException()
return path
def get_path_windows():
# ------------------------------ #
# Uses util dir to find the path of Chrome
# ------------------------------ #
path = (os.popen("""dir "chrome.exe" /s""").read().strip())
if len(path) == 0:
raise PathNotFoundException()
return path
def get_path_linux():
# ------------------------------ #
# Uses util which to find the path of Chrome
# ------------------------------ #
path = (os.popen("""which google-chrome""").read().strip())
if len(path) == 0:
raise PathNotFoundException()
return path
def get_path():
if "Darwin" in platform.system():
return get_path_macos()
elif "Windows" in platform.system():
return get_path_windows()
elif "Linux" in platform.system():
return get_path_linux()
if __name__ == "__main__":
print(get_path())