-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitForDock.py
More file actions
65 lines (55 loc) · 2.01 KB
/
WaitForDock.py
File metadata and controls
65 lines (55 loc) · 2.01 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
#!/usr/bin/env python
"""Wait for Dock to launch."""
import subprocess
import sys
import time
# One million percent stolen almost verbatim from munki
def get_running_processes():
"""Return a list of paths of running processes."""
proc = subprocess.Popen(['/bin/ps', '-axo' 'comm='],
shell=False, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(output, dummy_err) = proc.communicate()
if proc.returncode == 0:
return [item for item in output.splitlines()
if item.startswith('/')]
return []
def is_app_running(appname):
"""Determine if the application in appname is currently running."""
proc_list = get_running_processes()
matching_items = []
if appname.startswith('/'):
# search by exact path
matching_items = [item for item in proc_list
if item == appname]
elif appname.endswith('.app'):
# search by filename
matching_items = [item for item in proc_list
if '/' + appname + '/Contents/MacOS/' in item]
else:
# check executable name
matching_items = [item for item in proc_list
if item.endswith('/' + appname)]
if not matching_items:
# try adding '.app' to the name and check again
matching_items = [item for item in proc_list
if '/' + appname + '.app/Contents/MacOS/' in item]
if matching_items:
# it's running!
print 'Matching process list: %s' % matching_items
print '%s is running!' % appname
return True
# if we get here, we have no evidence that appname is running
return False
def main():
"""Script workflow."""
# Wait for Dock to start
while is_app_running('Dock') is False:
print 'Waiting for Dock'
time.sleep(1)
time.sleep(4)
return 0
if __name__ == "__main__":
MAIN_RESULT = main()
sys.exit(MAIN_RESULT)