Page 1 of 1

Can't run scripts from inside Sublime Text - "could not close previous instance of this script. Keep waiting?"

Posted: 22 Oct 2019, 04:50
by Ross
I've been experiencing problems to reload my two main scripts after editing them on Sublime Text.

First, I thought it was a problem in Sublime Text's AutoHotKey package, SublimeAutoHotKey. So I removed it from ST and manually installed.

Then I opened a new small .ahk script I just created and hit Ctrl+B to have it built (run). It worked; the script which wasn't running fired up and showed its icon on the system tray. FYI the script has a single hotkey set, so it will keep running and showing its icon.

After editing it and hitting Ctrl+B in Sublime Text, it saved and executed the new version as expected. Good. Now it seems the problem is not in Sublime Text or the SublimeAutohotkey package.

Now the problem: my two main scripts, one for general macros and built-in subscripts (like NiftyWindows) and other for hotstrings (a lot now) can no longer be run from within Sublime Text. When I hit Ctrl+B to "build", it displays "building" in the status bar, but never updates to the latest version. The old version goes on running. Then, after a few seconds, it pops a message: "Could not close the previous instance of this script. Keep waiting?" I haven't had this problem until some weeks ago; prior to that, when I hit Ctrl+B, I could see the AHK icon in the system tray rapdly vanish then reload.

However, if those two scripts are not running, but their files are open in Sublime Text, hitting Ctrl+B will run them — and their icons will be loaded on the system tray. It just won't update if it's already running.

How to make it work again?

My scripts header boilerplates are as follows:

Code: Select all

SetWorkingDir, %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, tray, icon, ico/m.ico
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
Process, Priority, , High
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode, 2

Re: Can't run scripts from inside Sublime Text - "could not close previous instance of this script. Keep waiting?"

Posted: 09 Nov 2019, 13:15
by Ross
Anyone? I really need this... :(

Re: Can't run scripts from inside Sublime Text - "could not close previous instance of this script. Keep waiting?"

Posted: 09 Nov 2019, 13:37
by guest3456
Ross wrote:
22 Oct 2019, 04:50
When I hit Ctrl+B to "build", it displays "building" in the status bar, but never updates to the latest version. The old version goes on running. Then, after a few seconds, it pops a message: "Could not close the previous instance of this script. Keep waiting?" I haven't had this problem until some weeks ago; prior to that, when I hit Ctrl+B, I could see the AHK icon in the system tray rapdly vanish then reload.
maybe you added something new to those scripts which caused it to start failing? do you rememer what you might have changed 2 weeks ago? i supposed the scripts are large but i dont know how else this may be debugged

Re: Can't run scripts from inside Sublime Text - "could not close previous instance of this script. Keep waiting?"

Posted: 20 Nov 2019, 15:54
by Ross
Edit: Disregard the following; I found the cause and it has nothing to do with it:

Hi, sorry for the long time.

Yes, I 'kinda' remember what I did add. It was a routine to rename downloaded files and folders. Basically, I put the full path of the folder on the clipboard (say the folder is named C:\Downloads\ALL OVER THE WORLD) and do as follows:

[code]NewStr1 := RegExReplace(Clipboard, "i)(.+\\)", "")

NewStr2 := RegExReplace(NewStr1, "(A | About | After | Against | Among | An | And | Around | As | At | Before | Between | By | During | For | From | In | Into | Like | Of | Off | On | Or | Out | Over | The | Through | To | Under | With | Without | A | ABOUT | AFTER | AGAINST | AMONG | AN | AND | AROUND | AS | AT | BEFORE | BETWEEN | BY | DURING | FOR | FROM | IN | INTO | LIKE | OF | OFF | ON | OR | OUT | OVER | THE | THROUGH | TO | UNDER | WITH | WITHOUT)","$L1")

; Removed capitalization of words above; for now, only the first occurence.

NewStr3 := RegExReplace(NewStr2, "(A | About | After | Against | Among | An | And | Around | As | At | Before | Between | By | During | For | From | In | Into | Like | Of | Off | On | Or | Out | Over | The | Through | To | Under | With | Without | A | ABOUT | AFTER | AGAINST | AMONG | AN | AND | AROUND | AS | AT | BEFORE | BETWEEN | BY | DURING | FOR | FROM | IN | INTO | LIKE | OF | OFF | ON | OR | OUT | OVER | THE | THROUGH | TO | UNDER | WITH | WITHOUT)","$L1")

; Removed capitalization of words above; for now, only the first occurence.

NewStr4 := RegExReplace(NewStr3, "(A | About | After | Against | Among | An | And | Around | As | At | Before | Between | By | During | For | From | In | Into | Like | Of | Off | On | Or | Out | Over | The | Through | To | Under | With | Without | A | ABOUT | AFTER | AGAINST | AMONG | AN | AND | AROUND | AS | AT | BEFORE | BETWEEN | BY | DURING | FOR | FROM | IN | INTO | LIKE | OF | OFF | ON | OR | OUT | OVER | THE | THROUGH | TO | UNDER | WITH | WITHOUT)","$L1")

; Removed capitalization of words above; for now, only the first occurence.[/code]

The code above is incomplete, but you get the idea: I scan the string on the clipboard, which is C:\Downloads\ALL OVER THE WORLD then output it multiple times until all the words will be in starting caps unless they're on the list above; as you can see, those are not words suitable to remain in caps:

[code]C:\Downloads\ALL OVER THE WORLD
C:\Downloads\All Over The World
C:\Downloads\All over The World
C:\Downloads\All over the World[/code]

I'm positive the code above can be shortened (like the words list, which can be called without the need for litteral repetition, plus I know there is no need to list them twice, all in proper case, then all in caps), but so far I couldn't. But it was after I added 16 of the block above (to ensure it covers a folder with a big name) when I started getting the aforementioned error.