如何在Mac上制作SublimeText 2快捷方式来运行处理草图?

Ric*_*hez 13 processing build-automation sublimetext

我正在使用SublimeText 2来编写我的Processing草图,但是每次我需要运行程序时我都必须切换到Processing并单击Run按钮,Textmate有一个包来自动化这个过程,我想做同样的事情SublimeText但我不知道如何

顺便说一句,我正在使用Mac OSX Lion

tub*_*ous 5

感谢brunchstorm的建议!我修改了你的方法,以便在Sublime中打开的Processing文件可以直接发送到Processing应用程序.首先,我下载并安装了一个TextMate Processing软件包,以便在Sublime(http://www.onebitwonder.com/projects/processing)中将.pde文件正确识别(并以语法突出显示)为Processing documents .如果您浏览该tmbundle,则必须修改TextMate语言定义文件(Processing.tmbundle/Syntaxes/Processing.tmLanguage).在该文件的底部附近有一行:

<string>source.java-processing</string>

此行必须更改为:

<string>source.pde</string>

保存Processing.tmLanguage后,可以将整个Processing.tmbundle包放入Sublime包目录中.现在在Sublime中打开一个.pde文档.在Sublime窗口的右下角是一个文档类型标识符,可能会说"纯文本".单击该标识符并选择"打开所有当前扩展名为..."并选择"处理",现在应该在列表中.我编写了两个AppleScripts来启动和运行Processing以及一个shell脚本来驱动它们(这是我能够从Sublime顺序启动AppleScripts的唯一方法).

如果尚未运行,则第一个脚本将启动Processing.此步骤是必需的,因为如果Processing未运行,则必须先插入延迟,然后Processing才会注册击键(启动时会出现启动画面几秒钟).延迟3秒适用于我的系统,但您可能需要根据硬件延长延迟时间.也许其他人可以想出一种更优雅的方式来让AppleScript等待处理以超越启动画面.

第一个AppleScript(由我命名为"first_processing.scpt"):

--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
Run Code Online (Sandbox Code Playgroud)

第二个AppleScript发送一个键击以运行您的Processing程序(名为"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
Run Code Online (Sandbox Code Playgroud)

驱动程序shell脚本(名为"launch_processing_file.sh"):

osascript ~/Documents/AppleScript_Library/processing/first_processing.scpt
open -a Processing $1
osascript ~/Documents/AppleScript_Library/processing/second_processing.scpt
Run Code Online (Sandbox Code Playgroud)

最后,Sublime构建系统用于处理(存储在用户目录中,带有".sublime-build"扩展名):

{
    "cmd": ["sh", "full_path_to_shell_script/launch_processing_file.sh", "$file"],
    "selector": "source.pde"
}
Run Code Online (Sandbox Code Playgroud)

请注意,必须在"处理"首选项中选择"使用外部编辑器"才能使此方法正常工作.另请注意,您的Processing文件必须包含在具有相同名称的文件夹中.我可能会编写一个脚本来为一个裸处理文件创建正确的封闭文件夹,但是现在这个方面并没有自动处理.请享用!

PS

这是我在此的头一篇博文.多么棒的网站!


chr*_*ick 5

Brunchstorms解决方案的更新.这是目前最好的解决方案.比定制构建更好.一,安装处理,最新工作正常.

打开处理时,请按照以下说明操作:

http://wiki.processing.org/w/Command_Line

那会安装命令行工具,没什么大不了的,只需去工具 - >安装"processing-java"这个安装命令行工具

如果您没有为sublime安装软件包管理器,那么它非常简单,只需按照以下说明操作即可:

http://wbond.net/sublime_packages/package_control

只需复制粘贴!

现在,在Sublime Text 2中,您可以安装Processing Sublime Text 2插件,这样当您打开.pde时,只需按下命令+ b即可运行草图.加工甚至不需要开放!