mbigras Posted May 6, 2016 Share Posted May 6, 2016 I just found the Sublime Text Workflow which is totally awesome, thanks so much deanishe! It lets you use a keyword and then searches for your "{query}" in some directories which you can specify in a config file. I'm trying to modify the workflow a little bit so I can use a hotkey to open a specific project in sublime. The workflow can be seen below: Opening up the .st script filter we can see the following: I'm still new to Alfred and to scripting in general but it looks to me like the author is piping the input the user types into the Alfred search bar (as represented by "{query}") into a python script that he wrote, sublime.py, and then running it using the python interpreter that's found at /usr/bin/python (please correct me if I'm missing something here). The python script then takes the query and does it's thing to open up the desired project in sublime. So I thought maybe I'd be able to make a hotkey trigger to perform an action: Run a Script and pass it a specific argument which would be a path to one particular project; however, I haven't gotten it to work, please see below: How would I go about doing this? Also as a side note, I'm really interested in learning more about python or ruby scripting get different programs to talk to Alfred and Sublime but I've honestly been having a pretty tough time finding a comprehensive guide to this sort of thing. I think it's because most of my searching ends up finding examples of how to use Sublime to write ruby/python code but what I want to do is use ruby and python code to write scripts that talk to Sublime and/or Alfred. So recommendations for good tutorials on effective python/ruby script writing specifically pertaining to Alfred and Sublime would also be greatly appreciated. Thanks for your help Link to comment
deanishe Posted May 8, 2016 Share Posted May 8, 2016 Just connect your Hotkey to an Open File Action? Script Filters are for generating/filtering lists of results for Alfred. If you run a Script Filter script on the command line, it'll most likely just spit out a bunch of XML. Here's a tutorial on writing Alfred Script Filters with Python. It assumes you already know what Script Filters are. Here's a tutorial on writing Sublime Text plugins with Python. Link to comment
mbigras Posted May 8, 2016 Author Share Posted May 8, 2016 (edited) Edit: I found my issue already addressed in your github repo it looks like it's not possible to do yet. Oh well, thanks so much for the tutorials and help with my hotkey question thanks deanishe, that was definitely what I asked for. Also thanks for the tutorial recommendations, they look great (which is meant to be a compliment to you, as I see it looks like they're your tutorials . I might learn how to do this by going through the tutorials, but would be it possible to set up something like the following with alfred -Run hotkey shortcut to open sublime project file in sublime -if project is already running in sublime -bring project to focus -else -open project file in sublime and bring to focus The way I have it set up right now goes like: -Run hotkey shortcut to open sublime project file in sublime -if project is already running in sublime -open project file in sublime and bring to focus -else -open project file in sublime and bring to focus which is kind of a bummer because it causes me to open multiple instances of the same project when what I really want to do is easily get the my specific sublime project. Edited May 8, 2016 by mbigras Link to comment
deanishe Posted May 9, 2016 Share Posted May 9, 2016 (edited) -Run hotkey shortcut to open sublime project file in sublime -if project is already running in sublime -open project file in sublime and bring to focus -else -open project file in sublime and bring to focus Yeah, no go, I'm afraid. Although Sublime Text plugins (which run within Sublime) can do amazing things, Sublime isn't really scriptable from the outside. The closest you could get is looking at window titles (which are "XXX — <Project Name>") or by creating a Sublime Text plugin to work together with your external code. For example, I have a Sublime Plugin that writes the path to the current file to my home directory, so I can change directly to the directory open in Sublime Text from a shell. FWIW, my preferred solution for .sublime-project files is to open them with the subl CLI program. It opens projects with the correct files open, which the GUI app doesn't. What I did was create a simple application with AppleScript that calls subl and associate .sublime-project files with that application. Edited May 9, 2016 by deanishe Link to comment
mbigras Posted May 9, 2016 Author Share Posted May 9, 2016 (edited) Right on deanishe I hear you man. But this workaround you're talking about doesn't make sense to me yet. Are you saying that when you open a sublime project from the terminal it doesn't create multiple instances of that project? Because for me if I'm in the terminal and I say something like $ sublime some_project.sublime-project $ sublime some_project.sublime-project then it will create two instances of that project. Note also that I remapped by "subl" command to "sublime" but I don't think that should make a difference. Because if I'm understanding you correctly you could just route the keyword to that applescript and it would work fine...but maybe I'm confused. Edited May 9, 2016 by mbigras Link to comment
deanishe Posted May 9, 2016 Share Posted May 9, 2016 No, the subl command still opens the project multiple times. If you open a *.sublime-project file with Sublime Text.app, it forgets which files were open etc. If you open *.sublime-project files with the subl command-line program, it opens the same files and directories as last time. I created a wrapper application so I can associate *.sublime-project files with it, so they're opened via subl even when I double-click in Finder or indeed via the Sublime Text Projects workflow. Link to comment
mbigras Posted May 10, 2016 Author Share Posted May 10, 2016 I see what you're saying now, it's not that subl prevents multiple windows from being opened, it's that it saves the current state of the project so all your open views don't get deleted. It makes sense why you added the FWIW now because it's a cool trick, but it doesn't get us closer to preventing multiple projects from opening oh well. How about since we're going on tangents do you think any of this is related to the question I asked over in your repository *note: I totally know they're not related it just seems like I'm hearing back from you sooner over here Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now