Skip to content

Instantly share code, notes, and snippets.

@egel
Last active April 8, 2024 23:00
Show Gist options
  • Save egel/b7beba6f962110596660 to your computer and use it in GitHub Desktop.
Save egel/b7beba6f962110596660 to your computer and use it in GitHub Desktop.
Auto-remove Sublime's license popup
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sublime_plugin
import subprocess
from time import sleep
import sys
cl = lambda line: subprocess.Popen(line, shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
log = lambda message: sys.stderr.write("Log: %s\n" % message)
sublimeMainWindowTitle = " - Sublime Text (UNREGISTERED)"
class LicenseWindowKiller(sublime_plugin.EventListener):
def seek_n_close(self):
sublimePid = int(cl("""wmctrl -lp | grep "%s" | awk '{print $3}'""" % sublimeMainWindowTitle).decode())
if sublimePid:
sublimeMainWindowId = cl("""wmctrl -lp | grep "%s" | awk '{print $1}'""" % sublimeMainWindowTitle).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)
return True
return False
def on_pre_save_async(self, *args):
seek = True
counter = 10
while seek:
sleep(.5)
counter -= 1
if counter < 0:
seek = False
seek = not self.seek_n_close()
@tranghaviet
Copy link

add 127.0.0.1 license.sublimehq.com to your hosts file.

@Un1Gfn
Copy link

Un1Gfn commented May 10, 2018

@VMBindraban @michael13491 (ArchLinux) wmctrl works and no error. Many a thanks.

@ajsnyde
Copy link

ajsnyde commented May 16, 2018

Not working for me. Windows 10, running unregistered. Created plugin as per directions from cardaba.

@crimsonsoccer55
Copy link

Can't get it either

@mazzarito
Copy link

mazzarito commented May 26, 2018

This is only going to work on linux .. wmctrl doesn't exist on windows

@costabatista-dev
Copy link

It worked fine to me. Thanks. (Sublime 3)

@sharegrams
Copy link

Thank you, Egel!

This crap was so obnoxious. Especially if you have tons of files open and you have some scripts that are modifying the textfiles in the background. Meaning it's doing tons of counts on the incremental counter in the BG.

Made it unusable and frustrating.

@passooo
Copy link

passooo commented Sep 6, 2018

Awesome, it works on my laptop running Darwin.

@unicornlox
Copy link

It's a very simple procedure:

  1. Copy the script
  2. In ST3, open "Tools --> Developer --> New Plugin ...."
  3. Paste the script in the new file created.
  4. Save changes. Put ANY name just adding ".py" extension.
    You're done.
    You can check in the console if the plugin has been loaded by ST3 using the console. For example I used "killer.py" and you can see in the console:
    reloading plugin User.killer

killer.py is incorrect when typing, but the response is correct.

>>>import sublime_plugin
>>> sublime_plugin.reload_plugin('User.killer')
console output:
reloading plugin User.killer

@reallyquickturtle
Copy link

Has anyone gotten this to work on macOS? I've installed wmctrl using brew but I'm still getting ValueError: invalid literal for int() with base 10: ''

@ReverseSpidey
Copy link

Excelente! Muchas gracias.

@shamiul94
Copy link

It works like magic dude.

@CSharpFiasco
Copy link

CSharpFiasco commented Feb 24, 2019

For anyone trying to make this work, it looks like this will only work on Linux machines, not windows. What this program seems to be doing is running commands to try to get Process Ids (based off the window name) to determine which window to close. Of course those commands are going to be sensitive to the operating system. If you're using Linux, you'll probably need to install wmctrl.

If you're getting the error ValueError: invalid literal for int() with base 10: '', this is probably why.

Instructions by mrParabol should work if you meet the system requirements.

@ruped24
Copy link

ruped24 commented Feb 2, 2020

how do we run this? which directory should it be in ?

Give this standalone version a try:
https://gist.github.com/ruped24/a0fd0272a8ef56441cafb44c753310e0

@niamdiovcitatscilbup
Copy link

niamdiovcitatscilbup commented Jun 16, 2020

There is actually a windows solution, though maybe not quite as elegant. I got rid of that pop up using auto hotkey in Windows. It's been awhile, So I don't remember the specifics so you'll have to do some research on auto hotkey to implement this but AHK is super simple and easy to pick up - you should probably be able to do this in 10 to 15 minutes with no prior knowledge. But basically you can set sections of AHK code to only run when a certain window is active, you can do that by title or EXE or both. And basically what I did is while the main sublime window was active I did a check every probably one or two seconds to see if a window with that pop ups title was active and would use a click command to automatically click the x or cancel or whatever it was. There may be a function in autohotkey that will wait for a new window to pop up, and then you can get the title of that window rather than pulling from a loop but I'm not 100% sure on that one. I know the loop way will work the other one I'm not sure if even exists. But again the auto hockey website lays everything out very well and has all of its triggers very well explained.

@shirobachi
Copy link

It's awesome!

Is it possible to do the same for SFTP? It's package what do the same popup https://i.imgur.com/dUU7vIM.png

Thanks in advance!

@madzohan
Copy link

@shirobachi did you try this https://askubuntu.com/a/815987/652604 (it works for me without any services)?

@shirobachi
Copy link

@madzihan thanks but unfortunately it's not work in my case ;/

@luisvalenzuelar
Copy link

Works on Ubuntu 20.04 with build 3211, but only from second pop-up onward. The first one is show around the 5th save time. I can live with this.

Thanks!

@rohit-kumar-j
Copy link

rohit-kumar-j commented Jan 9, 2021

Hi! I found a solution:
image

Now Its gone:

image

Cheers!

@dominicsherry1
Copy link

ValueError: invalid literal for int() with base 10: ''
Writing file filename.js with encoding UTF-8 (atomic)
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 247, in on_pre_save_async
    callback.on_pre_save_async(v)
  File "/home/vijay/.config/sublime-text-3/Packages/own/windowKiller.py", line 36, in on_pre_save_async
    seek = not self.seek_n_close()
  File "/home/vijay/.config/sublime-text-3/Packages/own/windowKiller.py", line 17, in seek_n_close
    sublimePid = int(cl("""wmctrl -lp | grep "%s" | awk '{print $3}'""" % sublimeMainWindowTitle).decode())
ValueError: invalid literal for int() with base 10: ''

Seems your plugin doesn't work anymore.

I suspect the reason it's not working is because you don't have the wmctrl prerequisite installed.

sudo apt install wmctrl should resolve your issues.

@ultra-taco
Copy link

ultra-taco commented Feb 13, 2021

Confirmed NOT working on Mac OSX 10.15.7 (see edit)

  1. first you need wmctrl. I did brew install wmctrl and it installed over a HUNDRED dependencies, but it worked. If you dont have brew then just know its trivial to install, google it.
  2. follow instructions in the post by cardaba commented on Sep 15, 2017
  3. View the console to make sure it didn't throw any errors. Select sublime text -> View -> Show Console
  4. Save a document and look for errors in the console

EDIT: This is extremely flaky and does not work most of the time. Despite installing wmctrl, I still get errors regarding ValueError: invalid literal for int() with base 10: ''

@aliazhar-id
Copy link

does this plugin still work in sublime text build 4107?

@SudhanshuBlaze
Copy link

@aliazhar-id not working I'm on macOS, if you get any solution please help

@aliazhar-id
Copy link

@SudhanshuBlaze sorry I don't know, now I've moved to visual studio code.

@flora-le
Copy link

flora-le commented Jul 7, 2022

As others said, there is a code that prevents the pop up to show, but also prevents any pop up to show (tried to delete a folder, i couldn't because it was always closing). It was the code here that closes everything and i can't do anything

@kassbohm
Copy link

Thanks egel, but at the moment it's working in Linux - maybe because of this error:

killer.py", line 17, in seek_n_close sublimePid = int(cl("""wmctrl -lp | grep "%s" | awk '{print $3}'""" % sublimeMainWindowTitle).decode()) ValueError: invalid literal for int() with base 10: '741430\n741430'

@Silverbullet069
Copy link

Silverbullet069 commented Apr 19, 2023

I'm having the same error like @kassbohm had, have anybody figured out yet?

 line 17, in seek_n_close
    sublimePid = int(cl("""wmctrl -lp | grep "%s" | awk '{print $3}'""" % sublimeMainWindowTitle).decode())
ValueError: invalid literal for int() with base 10: ''

@DinleyH
Copy link

DinleyH commented Aug 18, 2023

Here is a working windows version: it works by closing the dialog box the moment it appears. its instant more or less, I never see the box anymore.

Windowkill.py

`import sublime_plugin
import ctypes
import time

TARGET_CLASS_NAME = "#32770"

class DialogBoxKiller(sublime_plugin.EventListener):

def close_dialog_boxes(self):
    EnumWindowsProc = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int))
    
    def get_window_class_name(hwnd):
        buff = ctypes.create_unicode_buffer(256)  # Assuming class name won't be longer than 256 characters
        ctypes.windll.user32.GetClassNameW(hwnd, buff, len(buff))
        return buff.value
    
    def enum_windows_callback(hwnd, lparam):
        class_name = get_window_class_name(hwnd)
        if class_name == TARGET_CLASS_NAME:
            ctypes.windll.user32.SendMessageW(hwnd, 0x0010, 0, 0)  # 0x0010 is WM_CLOSE
        return True

    ctypes.windll.user32.EnumWindows(EnumWindowsProc(enum_windows_callback), 0)
    
def on_pre_save_async(self, *args):
    time.sleep(0.1)  # Brief delay to ensure dialog has time to appear if it does
    self.close_dialog_boxes()

`

FYI this also works with SFTP.

@DinleyH
Copy link

DinleyH commented Aug 18, 2023

For a working windows version and instructions on how to install sublime plugins:

https://gist.github.com/DinleyH/e222834ddb3533d59fd7cafccf612f07

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