13

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

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

4

4 回答 4

5

Brunchstorms 解决方案的更新。这是当前的最佳解决方案。比自定义构建更好。一、安装处理,最新作品正常。

当您打开处理时,请遵循以下说明:

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

这将安装命令行工具,没什么大不了的,只需转到 Tools->install "processing-java" 这个安装命令行工具

如果你没有为 sublime 安装包管理器,这很简单,只需按照以下说明进行操作:

http://wbond.net/sublime_packages/package_control

只需复制和粘贴!

现在,在 Sublime Text 2 中,您可以安装 Processing Sublime Text 2 插件,因此当您打开 .pde 时,您只需按 command+b 即可运行草图。处理甚至不需要打开!

于 2013-03-27T23:51:24.707 回答
5

感谢早午餐风暴的建议!我修改了您的方法,以便可以将在 Sublime 中打开的处理文件直接发送到处理应用程序。首先,我下载并安装了一个 TextMate 处理包,以便将 .pde 文件正确识别(和语法高亮)作为 Sublime 中的处理文档(http://www.onebitwonder.com/projects/processing)。如果您浏览该 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 脚本来驱动它们(这是我可以让 AppleScripts 依次从 Sublime 正确启动的唯一方法)。

如果第一个脚本尚未运行,则启动处理。此步骤是必要的,因为如果 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

第二个 applescript 发送一个击键来运行您的处理程序(名为“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

驱动程序外壳脚本(名为“launch_processing_file.sh”):

osascript ~/Documents/AppleScript_Library/processing/first_processing.scpt
open -a Processing $1
osascript ~/Documents/AppleScript_Library/processing/second_processing.scpt

最后,用于处理的 Sublime 构建系统(以“.sublime-build”扩展名存储在您的用户目录中):

{
    "cmd": ["sh", "full_path_to_shell_script/launch_processing_file.sh", "$file"],
    "selector": "source.pde"
}

请注意,您必须在“处理”首选项中选择“使用外部编辑器”,此方法才能正常工作。另请注意,您的处理文件必须包含在同名文件夹中。我可能会编写一个脚本来为裸处理文件创建适当的封闭文件夹,但目前这方面并没有自动处理。享受!

附言

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

于 2012-05-08T18:45:19.067 回答
1

我把它作为一种快速的方法来使用 command+B 来运行您正在编辑的处理草图。

这是 sublime 中的构建文件.... (Tools->Build System->New Build System

{
    "cmd": ["osascript", "/PathTo/RunProcessing.scpt"]
}

这是它使用的applescript文件......

--------------------

tell application "Processing"
    activate
end tell

tell application "System Events"
    keystroke "r" using command down
end tell

--------------------

于 2012-03-23T14:28:50.340 回答
0

Tools > Build System > New Build System

这将允许您创建一个可以由保存触发Ctrl+B或设置为在保存时构建的构建系统。

于 2012-03-04T07:10:52.327 回答