在textwrangler中使用applescript将代码发送给julia

时间:2014-04-18 10:55:16

标签: applescript

我正在尝试设置一个TextWrangler脚本,该脚本会自动将所选代码发送给Julia。从执行将代码发送到R的作业的类似脚本中复制一点我尝试了脚本

tell application "TextWrangler"
    set the_selection to (selection of front window as string)

    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell

tell application "Julia-0.2.1"
    activate
    cmd the_selection
end tell

它不起作用。可能是因为包含“cmd the_selection”的行。有人建议如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

Julia不具有脚本功能,因此您无法以这种方式发送代码。你可以试试这个:

do shell script "julia -e '" & the_selection & "'"

这相当于在终端窗口中键入命令。根据您选择的具体内容,您可能需要先将其另存为文件,然后再传递文件路径。另请注意,如果julia不在您的路径中(如果您刚刚将Julia应用程序复制到Applications文件夹中),则需要指定.app包中实际可执行文件的完整路径: /Applications/Julia-0.2.1.app/Contents/Resources/julia/bin/julia

答案 1 :(得分:0)

如果Julia不像@khagler那样可编写脚本,那么你通常可以使用gui脚本。只要Julia有一个编辑菜单并且粘贴的键盘快捷键是cmd-v(就像在大多数应用程序中一样)并且光标放在适当的位置以使粘贴工作,这将有效。祝你好运。

tell application "TextWrangler"
    set the_selection to (selection of front window as string)

    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell

set the clipboard to the_selection

tell application "Julia-0.2.1" to activate
delay 0.2
tell application "System Events" to keystroke "v" using command down

编辑 :我在评论中看到每次运行脚本时都会打开一个新的Julia窗口。这可能是因为这条线而发生的......告诉应用程序" Julia"激活。您可以尝试使用这一行代码。这是在发出击键命令之前将Julia带到最前面的另一种方法。

tell application "System Events" to tell process "Julia-0.2.1" to set frontmost to true

请注意,如果这并未将Julia窗口置于最前面,那么因为进程名称错误。有时,进程名称与应用程序名称不同。如果是真的,你必须弄清楚Julia过程的名称,你可以通过运行它并查找它的名字来做。您可能必须使用"终端"如果朱莉娅在终端窗口中运行。

tell application "System Events" to return name of processes