-
Notifications
You must be signed in to change notification settings - Fork 62
/
__init__.py
90 lines (71 loc) · 2.48 KB
/
__init__.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
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
from subprocess import call
class MacBrowserRefresh:
def __init__(self, activate_browser):
if activate_browser:
self.activate = 'activate'
else:
self.activate = ''
self._chrome_applescript = """
tell application "{name}"
{activate}
set winref to a reference to (first window whose title does not start with "Developer Tools - ")
set winref's index to 1
reload active tab of winref
end tell
"""
def _chrome(self, app_name, browser_name):
command = self._chrome_applescript.format(
name=app_name, activate=self.activate)
self._call_applescript(command)
def chrome(self):
self._chrome("Google Chrome", "chrome")
def canary(self):
self._chrome("Google Chrome Canary", "canary")
def yandex(self):
self._chrome("Yandex", "yandex")
def safari(self):
command = """
tell application "Safari"
{activate}
tell its first document
set its URL to (get its URL)
end tell
end tell
""".format(activate=self.activate)
self._call_applescript(command)
def webkit(self):
command = """
tell application "WebKit"
{activate}
tell its first document
set its URL to (get its URL)
end tell
end tell
""".format(activate=self.activate)
self._call_applescript(command)
def firefox(self):
command = """
tell application "Firefox"
activate
tell application "System Events" to keystroke "r" using command down
end tell
"""
self._call_applescript(command)
def firefox_dev(self):
command = """
tell application "FirefoxDeveloperEdition"
activate
tell application "System Events" to keystroke "r" using command down
end tell
"""
self._call_applescript(command)
def opera(self):
command = """
tell application "Opera"
activate
tell application "System Events" to keystroke "r" using command down
end tell
"""
self._call_applescript(command)
def _call_applescript(self, command):
call(['osascript', '-e', command])