Skip to content

Instantly share code, notes, and snippets.

@ruped24
Last active August 13, 2023 02:37
Show Gist options
  • Save ruped24/a0fd0272a8ef56441cafb44c753310e0 to your computer and use it in GitHub Desktop.
Save ruped24/a0fd0272a8ef56441cafb44c753310e0 to your computer and use it in GitHub Desktop.
Auto-remove SublimeText3 license popup
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
# forked from egel/auto-remove-sublime-license-popup
# https://gist.github.com/egel/b7beba6f962110596660
from commands import getoutput as cl
from threading import Event, Thread
from sublime_plugin import EventListener
sublimeMainWindowTitle = " - Sublime Text"
class LicenseWindowKiller(EventListener):
def seek_n_close(self):
sublimePid = int(
cl(
"""wmctrl -lp \
| grep "%s" \
| awk '{print $3}'""" % 'Sublime Text'
).decode()
)
if sublimePid:
sublimeMainWindowId = cl(
"""wmctrl -lp \
| grep "%s" \
| awk '{print $1}'""" % 'Sublime Text'
).decode()
sublimeSecondWindowId = cl(
"""wmctrl -lp \
| grep %s \
| awk '{ids[$1]++}{for (id in ids){if (id != "%s"){printf id}}}'"""
% (sublimePid, sublimeMainWindowId)
).decode()
if sublimeSecondWindowId:
sublimeSecondWindowTitle = cl(
"""wmctrl -lp \
| grep %s \
| awk '{print $5}'""" % sublimeSecondWindowId
).decode()
if not sublimeSecondWindowTitle:
cl("wmctrl -i -c %s" % sublimeSecondWindowId)
self._remove_popup.set()
self._remove_popup.is_set()
class ListenerLoop(LicenseWindowKiller, Thread):
def __init__(self):
super(Thread, self).__init__()
super(self.__class__, self).__init__()
self._remove_popup = Event()
self.remove_popup = Thread(target=self.on_pre_save_async)
self.start()
def on_pre_save_async(self):
try:
counter = 600
while not self._remove_popup.is_set():
self._remove_popup.wait(.01)
counter -= 1
if counter < 0:
seek = self._remove_popup.set()
seek = self.seek_n_close()
except ValueError:
pass
def run(self):
self.remove_popup.start()
if __name__ == "__main__":
ListenerLoop()
@ruped24
Copy link
Author

ruped24 commented Feb 2, 2020

  • Register Sublime Text
  • ⚠️ Add: sudo chattr +i License.sublime_license
  1. Launch sublime-text-3.
  2. Start this standalone script: python auto-remove-sublime3-license-popup.py
  3. To autorun: Put in a Shell script, sleep (1) second after sublime_text.

That's it. 🔢

@shaiksamad
Copy link

is this for windows?

@ruped24
Copy link
Author

ruped24 commented Jul 19, 2020

is this for windows?

Sorry, Linux only.
Windows OS doesn't support wmctrl window manager.

@SudhanshuBlaze
Copy link

@ruped24 how do we put it in a shell script which runs it after starting of sublime

@ruped24
Copy link
Author

ruped24 commented Feb 21, 2022

How do we put it in a shell script which runs it after starting of sublime

#! /bin/bash
cd /usr/local/bin/sublime_text_3/ &> /dev/null \
&& ./sublime_text "$@"
sleep 1.5; 
python2 $HOME/.local/bin/auto-remove-sublime-license-popup.py &> /dev/null 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment