Jump to content

Sublime Text’s `subl` hangs when called from Alfred [Fixed 3.4 b843 pre-release]


Recommended Posts

References another post.

  1. Install Sublime Text. Latest version is 3 (3126). No other versions were tested.
  2. Link its CLI tool (/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl) to /usr/local/bin.
  3. Setup a simple Alfred Workflow. A single Keyword connected to a single Run Script that just reads /usr/local/bin/subl. Optionally, connect another node to the Run Script (this is to demonstrate it does indeed hang). Here is a ready-made workflow.
  4. Run the Workflow’s Keyword.
  5. Notice how Sublime Text does not show up, and anything connected after the Run Script does not run.
  6. Check the running processes, and verify subl is indeed running.

If you run subl from a shell or a script, it behaves normally. It is just when it’s called from Alfred (even if Alfred is calling a script that calls subl) that it hangs. Everything else seems to behave correctly.

There is something about that Alfred + subl connection that simply hangs. Maybe it’s a problem with subl, but there’s a chance this is a problem in Alfred that by chance only subl is triggering. Opening the bug report in case it’s the latter.

Link to comment
Share on other sites

6 minutes ago, deanishe said:

I think subl is hanging because it's in "wait" mode (no idea why this happens in Alfred, though).


That was my initial thought and I even downloaded it (I was debugging this for the linked thread) to check it waiting was its default behaviour and it had a --no-wait flag, or something.

But then what’s weird is that with Atom it works every time, including if you pass it the --wait flag.

Link to comment
Share on other sites

There's definitely something weird going on: If I call subl via Python's subprocess API, it behaves exactly as you'd expect (Sublime activates, subl exits).


I've tried running subl via NSTask (the API Alfred uses), and it behaves differently to when called via Python or straight from a shell. It doesn't hang like in Alfred, but it does open a temporary file read from STDIN, which it shouldn't.


Seems that subl doesn't get along with NSTask, rather than it being specifically Alfred. Most likely something to do with STDIN.

Edited by deanishe
Link to comment
Share on other sites

  • Andrew changed the title to Sublime Text’s `subl` hangs when called from Alfred [Accepted]

@vitor @deanishe So I've been playing with this a little, and have managed to reproduce it with a simple Run Script set to PHP setup to read from STDIN. By Alfred cleanly closing STDIN before reading to the end of the STDOUT buffer, it prevents the PHP Run Script from waiting indefinitely.


I've just done a 3.4 b834 pre-release which includes this fix, and I'd appreciate if you could verify this change a bit holistically for normal workflow operation (as it's part of Alfred's fundamental framework).


Let me know how you get on :)




Link to comment
Share on other sites

  • Andrew changed the title to Sublime Text’s `subl` hangs when called from Alfred [Fixed 3.4 b843 pre-release]

It doesn't hang, but it also doesn't work as it should. It's now working the same as my NSTask test: it opens a temp file with the data read from STDIN (i.e. an empty file). It should only activate the Sublime Text application.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...