Home Download Buy Blog Forum Support

Sublime Text plugins from command line

Sublime Text plugins from command line

Postby fatboy on Mon Jun 18, 2012 4:12 pm

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...
fatboy
 
Posts: 12
Joined: Mon Jan 16, 2012 11:41 pm

Re: Sublime Text plugins from command line

Postby jps on Tue Jun 19, 2012 6:02 am

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

Code: Select all
subl --command 'echo {"arg":42}'
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: Sublime Text plugins from command line

Postby C0D312 on Tue Jun 19, 2012 8:23 pm

TIL
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Sublime Text plugins from command line

Postby fatboy on Tue Jun 19, 2012 10:08 pm

I almost didn't ask, so sure I was that I couldn't. Thanks Jon.
fatboy
 
Posts: 12
Joined: Mon Jan 16, 2012 11:41 pm

Re: Sublime Text plugins from command line

Postby fatboy on Tue Jun 19, 2012 11:39 pm

I've hit a stumbling block.

if I run this from the terminal:

Code: Select all
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:

Code: Select all
#!/usr/bin/ruby
`subl --command  'goto_line {"line":50}'`

or this applescript:

Code: Select all
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?
fatboy
 
Posts: 12
Joined: Mon Jan 16, 2012 11:41 pm

Re: Sublime Text plugins from command line

Postby C0D312 on Wed Jun 20, 2012 12:05 am

If you're just trying to go to a particular line, you can do
Code: Select all
subl somefile.txt:50
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Sublime Text plugins from command line

Postby fatboy on Wed Jun 20, 2012 10:53 am

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
fatboy
 
Posts: 12
Joined: Mon Jan 16, 2012 11:41 pm

Re: Sublime Text plugins from command line

Postby jps on Sat Jun 23, 2012 5:47 am

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.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: Sublime Text plugins from command line

Postby wpguide on Sat Aug 25, 2012 10:48 pm

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

Code: Select all
subl --command 'select_line {"line":50}'
wpguide
 
Posts: 1
Joined: Sat Aug 25, 2012 10:44 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests