Sublime Forum

Run package command from command line

#1

Hi
I can’t find by search the right syntax how to run command from command line.
Now I am doing like this

0 Likes

#2

It depends. Before running a command from the command palette, you need to understand the concept of, what a view & window is in Sublime Text.

A view represents the file (or tab) you have open & it is created for every tab or file you have open.

A window represents the entire window and is created for every window you have open.

These are simplified definitions but in technical terms, these are python objects stored in memory.

Say for example, you have a plugin that extends TextCommand

import sublime
import sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        print("Hello, World")

To run such a command, you would do view.run_command("example") from the console. In short, TextCommand's are generally view based.

If you have a plugin that extends WindowCommand,

import sublime
import sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self, edit):
        print("Hello, World")

To run such a command, you would do window.run_command("example") from the console. In short, WindowCommand's are generally window based.

There are also ApplicationCommand's but that are rarely used. If you are curious, they are created once for every instance of the application you have running.

If the plugin takes arguments, then the way is :-
view.run_command("example", { "arg1": "value1", "arg2": "value2" }) etc

As a tip, window.run_command() can run any type of command, so if you are unsure of what type the command is, it is best to go with this.

Coming back to your screenshot, that command is probably not a part of the default command & looks like something you added or a part of a package/plugin you installed. In that case, you’ll have to either inspect what type the command is (by maybe inspecting the source code or reading the docs, if any) and to see if it takes any argument.

1 Like

#3

Thanks a lot for detail answer!

How its possible to inspect what type of command in package? What I need to open to understand what type command is?
In my screenshot its command from sidebar enhancements package?

0 Likes

#4

You could look through the source code of SideBarEnhancements package & see where SideBarNewFile2 command class is defined and then see what type of command it is.
Or else, I guess even window.run_command("side_bar_new_file2") might work.

1 Like