Sublime Forum

Terminal Command to close ST3

#1

This has turned out to be harder than I expected, as all the research so far is all about killing processes (in this case ST3), which unfortunately produces a different end state (and thus beginning state on restart), rather than closing ST3.
ie

 pkill -TERM sublime

produces a different outcome to ctrl+q from, within Sublime.

One can start Subime with the subl command (at command line) I was wondering if there was a command to close sublime rather than kill the sublime process.

It does make a difference. I’m running linux MATE, ST3.2.1.1

Am hoping (niaively) it might be something like xsubl, or subl_quit or lbus (ho ho ho)

Ta very muchly !

0 Likes

#2

You can pass commands to Sublime via subl --command, and the command for quitting Sublime is exit, so:

subl --command exit

Note however that you want to make sure that Sublime’s not already running when you do it, because the first thing subl does is check if Sublime is running and launch it if it’s not. In a case like that, the command you provide is (usually) ignored because the plugin host isn’t ready to accept commands right at startup, so the command falls on deaf ears.

The exit command by contrast will always work because it’s implemented in the core (and thus the plugin host is bypassed), but in that case you’re starting Sublime to ask it to stop, which doesn’t make a lot of sense.

0 Likes

#3

I don’t think I’m doing any of the above, sublime will be running, I just want to turn it off ‘nicely’. This is a small part to a larger puzzle.

Just what I was looking for, ta ! :blush:

0 Likes

#4

Ha ha, I’ve made a mistake, can I close a project from the command line ?

eg (pseudo code of what that command might look like)

subl --project /blar/blar/project_name close

:thinking:

0 Likes

#5

The command for closing a project is close_workspace; it will close the project in the currently active window.

Note that --project is for loading a project; presumably the project is already loaded if you’re trying to close it, so you probably don’t want that.

0 Likes

#6

Yep, it was just pseudo code to give an idea of what I wanted, I’ll edit.

Also would the full commandline command be (I’ve had a look at the page @rwols posted, but to no avail)

subl close_workspace /path_to_workspace/workspace_name

(I’ve just tried subl close_workspace and ST3 has opened a blank file called close_workspace)

Thank you !

0 Likes

#7

Where did you learn about close_workspace?

I could only find close_window: https://docs.sublimetext.io/reference/commands.html#close-window

0 Likes

#8

It’s in the Main.sublime-menu file:

{ "command": "close_workspace", "caption": "Close Project", "mnemonic": "C" },
1 Like

#10

I’ve tried using the info you’ve given me to try and solve myself (ie how to use close_workspace) but unfortunately I stuck with the vaguries of google and the documentation.
This is the best I’ve found (everything else is posts about build systems when i google “command Sublime Text 3 close_workspace”):

https://sublime-text-unofficial-documentation.readthedocs.io/en/sublime-text-2/reference/commands.html

I can’t find close_workspace in the documentation.

I’ve tried a few variants of subl --command close_workspace, but to no avail.

(Queue Gru out of Despicable 3 when he’s talking about catching Balthazar Bratt to his new boss, Valerie Da Vinci (at the AVL), “Soooooooo close, really really close” (fingers really close together))

One for the mature members of the forum there…

0 Likes

#11

Well, if you were to open the Sublime console and sublime.log_commands(True) and then, in a window that has a project open in it use Project > Close Project, you would see this in the console:

>>> sublime.log_commands(True)
command: close_workspace

So, despite whether the command happens to be documented or not, it’s observably there.

Similarly, if you were to have exactly 1 Sublime window open, AND that window was to have a project open in it (verifiable by checking that Project > Close Project is not grayed out), then from a terminal execute subl --command close_workspace, the window should close (it does here, in both ST3 and ST4).

On the other hand, if the window doesn’t have a project in it, then all the command should do is give the focus to Sublime without doing anything. Is that what you’re seeing?

From the context of your other posts, it sounds like you have many windows open with many projects in them; if you want to close a specific one from the terminal you’re going to need to use some wmctrl magic to make sure the window with the appropriate title (and hence project) has the focus first, if that helps matters any.

0 Likes

#12

Hi

I wasn’t disputing the existance of the command (I trust you implicitly, or as much as I trust any human being) it was just I can’t find any info on it, like what arguments to pass to it etc etc.

In summary: If I want to automatically close a specific project (in a specific Linux Workspace) from the Linux Terminal Commandline, I’ll have to focus on that workspace (some linux magic) then execute subl –command close_workspace.

(More in a bit, just gonna do some experimenting)

0 Likes