Sublime Forum

Launching .sublime-project file in Python

#1

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:

import subprocess
subprocess.Popen('open', '-a', 'Sublime Text 2', '/path/to/file.sublime-project'])

Though that doesn’t work.

I’ve also tried:

import os
os.system("open /path/to/file.sublime-project");

Though that doesn’t work either!

Any ideas would be greatly appreciated!

Thanks,

Chris

0 Likes

#2

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.

subl --project <project>
0 Likes

#3

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

I setup a symlink to subl, and then ran:

import subprocess
subprocess.call('subl --project /path/to/file.sublime-project'])

Though I get an error

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:

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

0 Likes

#4

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:

import desktop
desktop.open('/path/to/file')

Thanks for your help!

0 Likes

#5

[quote=“christoph2k”]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:

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[/quote]

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’

subprocess.call('subl', '--project', '~/Desktop/file.sublime-project'])
0 Likes