I'm using SublimeText 2 to code my Processing sketches, but every time I need to run the program I have to switch to Processing and click the Run button, Textmate have a bundle to automate this process and I would like to do the same with SublimeText but I've no idea how
I'm using Mac OSX Lion by the way
Thanks for the advice brunchstorm! I modified your method so that the Processing file open in Sublime can be sent directly to the Processing application. First, I downloaded and installed a TextMate Processing package so that .pde files would be correctly identified (and syntax-highlighted) as Processing documents in Sublime ( http://www.onebitwonder.com/projects/processing ). If you browse that tmbundle, there is a TextMate language definition file (Processing.tmbundle/Syntaxes/Processing.tmLanguage) that must be modifed. Near the bottom of that file there is a line:
<string>source.java-processing</string>
This line must be changed to:
<string>source.pde</string>
After you save Processing.tmLanguage, you can drop the entire Processing.tmbundle package into your Sublime packages directory. Now open a .pde document in Sublime. In the bottom-right corner of the Sublime window is a document type identifier that will probably say "Plain Text". Click on that identifier and pick "Open all with current extension as..." and choose "Processing", which should now be in the list. I wrote two AppleScripts to launch and run Processing and a shell script to drive them (this is the only way I could get the AppleScripts to launch correctly from Sublime in sequence).
The first script launches Processing if it is not already running. This step is necessary because if Processing is not running, a delay must be inserted before Processing will register keystrokes (a splash screen appears for several seconds during startup). A delay of 3 seconds works well with my system, but you may need to lengthen the delay depending on your hardware. Perhaps somebody else can think of a more elegant way to make AppleScript wait for processing to get past the splash screen.
First AppleScript (named "first_processing.scpt" by me):
--check to see if Processing is running
tell application "System Events"
set x to (count (every process whose creator type is "Pde1"))
end tell
--if Processing is not running, open Processing and delay
--for three seconds to allow time for splash screen
--to disappear and to allow keystrokes to be
--registered
if x is 0 then
activate application "Processing"
delay 3
end if
The second applescript sends a keystroke to run your Processing program (named "second_processing.scpt"):
tell application "Processing"
activate
end tell
tell application "System Events"
--deliver the "run" command
delay 0.1
keystroke "r" using command down
--hide Processing; delay is necessary for reliable hiding
--you may want to turn off hiding to see error messages
delay 0.2
keystroke "h" using command down
end tell
The driver shell script (named "launch_processing_file.sh"):
osascript ~/Documents/AppleScript_Library/processing/first_processing.scpt
open -a Processing $1
osascript ~/Documents/AppleScript_Library/processing/second_processing.scpt
Finally, the Sublime build system for Processing (to be stored in your user directory with a ".sublime-build" extension):
{
"cmd": ["sh", "full_path_to_shell_script/launch_processing_file.sh", "$file"],
"selector": "source.pde"
}
Note that you must choose "Use external editor" in the Processing preferences for this method to work correctly. Also note that your Processing file must be contained in a folder with the same name. I may write a script to create the proper enclosing folder for a bare Processing file, but for now that aspect is not taken care of automatically. Enjoy!
P.S.
This is my first post here. What a fantastic site!
An update to Brunchstorms solution. Here is the current best solution. Better than custom build. First, install processing, latest works fine.
When you open processing follow these instructions:
http://wiki.processing.org/w/Command_Line
That will install the command line tools, nothing tricky about it, just go Tools->install "processing-java" this install command line tools
If you don't have the package manager installed for sublime, it's very simple, just follow these instructions:
http://wbond.net/sublime_packages/package_control
just copy and paste!
Now, in Sublime Text 2 you can install the Processing Sublime Text 2 plugin so when you open a .pde you can simply hit command+b and it will run the sketch. Processing doesn't even need to be open!
I hacked this together as a quick way to use command+B to run processing sketches you are editing.
This is the build file in sublime.... (Tools->Build System->New Build System
{
"cmd": ["osascript", "/PathTo/RunProcessing.scpt"]
}
and this is the applescript file it uses...
tell application "Processing"
activate
end tell
tell application "System Events"
keystroke "r" using command down
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With