Sublime Forum

Sublime Text plugins from command line

#1

Is there a way to invoke Sublime Text’s plugins from the command line?

I’m looking for a way to include ST2 in a grander workflow with other applications under OSX.

I was hoping to use something along the lines of Applescript’s ‘do shell script’ command…

0 Likes

#2

You can use --command for this, e.g.:

subl --command 'echo {"arg":42}'
0 Likes

#3

TIL

0 Likes

#4

I almost didn’t ask, so sure I was that I couldn’t. Thanks Jon.

0 Likes

#5

I’ve hit a stumbling block.

if I run this from the terminal:

subl --command  'goto_line {"line":50}'

it works, the caret is now at the start of line 50.

but if I run this ruby script:

#!/usr/bin/ruby `subl --command 'goto_line {"line":50}'`
or this applescript:

do shell script "subl --command  'goto_line {\"line\":50}'"

ST2 will create a new document with a name like “subl stdin cGRGGe.txt” and the script task will not end until I close this new document.

I’m baffled. Does anyone know what might be going on?

0 Likes

#6

If you’re just trying to go to a particular line, you can do subl somefile.txt:50

0 Likes

#7

Yeah, interesting. That method works from my scripts. I still hope to get the other method working too, as I’d like to be able to invoke any command, not just goto_line.

Fb

0 Likes

#8

subl has slightly different behaviour on OS X if not run from a tty, when no files are present on the command line, to support piping to stdin without having to specify ‘-’. I’ll tweak the logic for the next build so this works as expected when --command is present.

0 Likes

#9

Is there somewhere that lists the available commands? I tried changing the command to select_line, but it hadn’t any effect.

subl --command 'select_line {"line":50}'
0 Likes