Home Download Buy Blog Forum Support

Launching .sublime-project file in Python

Launching .sublime-project file in Python

Postby christoph2k on Thu Jul 19, 2012 9:12 pm

Hello,

I'm looking for a way to launch a .sublime-project file in Sublime Text 2, so that it loads up all of the project files etc. As opposed to opening it to edit it.

I've tried:
Code: Select all
import subprocess
subprocess.Popen(['open', '-a', 'Sublime Text 2', '/path/to/file.sublime-project'])

Though that doesn't work.

I've also tried:
Code: Select all
import os
os.system("open /path/to/file.sublime-project");

Though that doesn't work either!

Any ideas would be greatly appreciated!

Thanks,

Chris
christoph2k
 
Posts: 6
Joined: Mon Jul 02, 2012 10:01 am

Re: Launching .sublime-project file in Python

Postby Xavura on Thu Jul 19, 2012 9:19 pm

This may help. As far as I can tell it's only available for Mac OS, for whatever reason but I think "open" is a Mac OS thing so that shouldn't be a problem.

Code: Select all
subl --project <project>
Xavura
 
Posts: 19
Joined: Sat Jul 14, 2012 4:40 pm

Re: Launching .sublime-project file in Python

Postby christoph2k on Fri Jul 20, 2012 7:33 am

Thanks for the suggestion, though that doesn't work.

I setup a symlink to subl, and then ran:

Code: Select all
import subprocess
subprocess.call(['subl --project /path/to/file.sublime-project'])


Though I get an error
Code: Select all
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 470, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory


I've tried changing the path to the file, I put it on my desktop and then used:
Code: Select all
subprocess.call(['subl --project ~/Desktop/file.sublime-project'])


Though the error is still the same.

I also was hoping for a multi-platform way to do this.

Thanks,

Chris
christoph2k
 
Posts: 6
Joined: Mon Jul 02, 2012 10:01 am

Re: Launching .sublime-project file in Python

Postby christoph2k on Fri Jul 20, 2012 1:05 pm

I found out about a module called desktop http://pypi.python.org/pypi/desktop.

This allows you to open a file with its native application:
Code: Select all
import desktop
desktop.open('/path/to/file')


Thanks for your help!
christoph2k
 
Posts: 6
Joined: Mon Jul 02, 2012 10:01 am

Re: Launching .sublime-project file in Python

Postby DisposaBoy on Sat Jul 21, 2012 9:09 am

christoph2k wrote:Thanks for the suggestion, though that doesn't work.
[...]
I've tried changing the path to the file, I put it on my desktop and then used:
Code: Select all
subprocess.call(['subl --project ~/Desktop/file.sublime-project'])


Though the error is still the same.

I also was hoping for a multi-platform way to do this.

Thanks,

Chris


Just FYI. That doesn't work because you're passing the wrong argument to subprocess.call. It should be as follows. Note that each component in the command is a string by itself. The first entry in the list is the command. In your code you're trying to execute a command called 'subl --pro...' not 'subl'

Code: Select all
subprocess.call(['subl', '--project', '~/Desktop/file.sublime-project'])
DisposaBoy
 
Posts: 23
Joined: Tue Aug 23, 2011 3:39 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron