-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
FocusSublimeWindow.py
39 lines (33 loc) · 1.16 KB
/
FocusSublimeWindow.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
import os
import sublime
import subprocess
from sublime_plugin import WindowCommand
NATIVE_FOCUS_WINDOW = int(sublime.version()) >= 4067
class FocusSublimeWindowCommand(WindowCommand):
"""
Focuses the SublimeText window.
"""
def run(self, **args):
if NATIVE_FOCUS_WINDOW:
self.window.bring_to_front()
platform = sublime.platform()
if platform == 'linux':
os.system(
'sh -c "xdotool windowactivate $(xdotool search --class sublime | tail -1)"'
)
elif platform == 'osx':
script = """
tell application "Sublime Text"
activate
end tell
""" # Brings ALL the windows forward
subprocess.Popen(["osascript", "-e", script])
elif platform == 'windows':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
subprocess.Popen(
'powershell -Command (New-Object -ComObject WScript.Shell).AppActivate({})'.format(
os.getppid()
),
startupinfo=startupinfo,
)