Sublime Forum

Run a Windows command from Sublime

#1

I am the developer of CSE HTML Validator for Windows and a customer inquired about integrating my software with Sublime. What I’d like to do is simply add a command to Sublime that causes Sublime run a Windows command with the filename of the current document being edited (preferably after saving it) so the user can open that document in my application and check it.

For example:
c:\path\command.exe -o <filename>

I am completely unfamiliar with Sublime and python. Can someone help me with this or point me somewhere that explains how to do this? Thanks in advance!

0 Likes

#2

Looks like a linter. You may write a plugin which works with SublimeLinter. (Developer Doc)

It’s simple. Basically you just need to writing following things.

  1. The command to invoke the linter.
  2. Regular expressions which are used to grep messages from the linter.
0 Likes

#3

Thanks. Yes, it is like a linter. SublimeLinter looks interesting and something that I may want to investigate in the future, but right now I simply want to have Sublime run a command that opens the current document in another program. It’s very simple to do in programs that allow you to add commands that run other commands, but I don’t see an easy way to do this in Sublime.

0 Likes

#4

In that case, maybe just write a build settings for HTML.

In HTML.sublime-build,

{
    "cmd": ["c:/path/command.exe", "-o", "${file}"],
    "working_dir": "${file_path}",
    "selector": "text.html" // or "text.html.basic"?
}

When users call a build command (Ctrl+B or Ctrl+Shift+B), it lints and the output would be in a panel.

2 Likes

#5

Thank you! This is much closer to what I want. This works:

{
	"cmd": ["C:\\Program Files (x86)\\HTMLValidator160\\cmdlineprocessor.exe", "-o", "${file}"]
}
  1. Since this command basically just opens the current document being edited (saving it first it seems), is there a way to suppress the panel from being opened?

  2. Also, do you know if there is an easy way to add a command that does the same thing to Sublime without using the build system? The build system works but it’s not really a build and seems more like a type of “hack”. Not a big deal if not.

  3. Finally, is there a way I can contact you privately? Or you could email me at support at htmlvalidator dot com? Thanks again.

0 Likes

#6

Since this command basically just opens the current document being edited (saving it first it seems), is there a way to suppress the panel from being opened?

Install Console Exec and modify build settings to

{
    "cmd": ["start", "C:\\Program Files (x86)\\HTMLValidator160\\cmdlineprocessor.exe", "-o", "${file}", "&&", "exit"],
    "selector": "text.html",
    "target": "console_exec" // this will start the build system with Windows' CMD window rather than a ST panel
}





Also, do you know if there is an easy way to add a command that does the same thing to Sublime without using the build system?

Write a plugin. Start a process by Popen or whatever.

The build system works but it’s not really a build and seems more like a type of “hack”.

Build system could have variants. ST uses it to do syntax check / syntax performance test / syntax regex compatibility test / etc… I don’t think it’s an inappropriate “hack.”

variants example:

{
    "cmd": ["node", "${file}"],
    "working_dir": "${file_path}",
    "selector": "source.js",
    "variants": [
        {
            "cmd": ["closure-compiler.jar", "--js", "${file}", "--js_output_file", "${file_base_name}-compiled.js"],
            "name": "Minify"
        },
    ]
}

I can either execute js files or compress them with the build system. It’s selectable.






Finally, is there a way I can contact you privately? Or you could email me at support at htmlvalidator dot com? Thanks again.

I guess no. I am not your private counselor. And other people don’t benefit from it if I contact you privately. Moreover, I am not the only person who could help you here. :stuck_out_tongue:

8 Likes

#7

OK, thanks for the help and examples. It definitely got me on the right path. Also, I was asking for your private contact info so I could offer you something you might find useful in return for your help… and didn’t want to do it publicly.

1 Like

#9

 

You can add a scope selector so that the build only shows up in the proper context:

{
	"cmd": ["C:\\Program Files (x86)\\HTMLValidator160\\cmdlineprocessor.exe", "-o", "${file}"],
	"selector": "text.html"
}

 
Otherwise, it will show up for all file types.

1 Like

#10

Thank you. What should it be if I want it to show up for HTML, CSS, JavaScript, PHP, and JSON? Is there a list somewhere of the possibilities? Sublime’s documentation doesn’t seem to be too good… or maybe I am missing something.

0 Likes

#11

##Multiple Selectors For Build Systems

 

 
Not that I know of, but you can easily find what you need by:

  • selecting the appropriate syntax from the syntax menu in the bottom right corner of the status bar

  • pressing Ctrl + Shift + Alt + P to show a list of scope selectors that apply to the current caret position ( displayed @ the status bar )

2 Likes