首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在textwrangler中使用applescript向julia发送代码

在textwrangler中使用applescript向julia发送代码
EN

Stack Overflow用户
提问于 2014-04-18 10:55:16
回答 2查看 389关注 0票数 0

我正在尝试设置一个TextWrangler脚本,自动将选定的代码发送给朱莉娅。从执行将代码发送到R的类似脚本中复制一点,我尝试了脚本

代码语言:javascript
复制
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“的行。有人建议怎么解决这个问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-18 19:09:46

好吧,如果朱莉娅不是像@khagler所说的那样有剧本的话,那么你通常可以使用gui脚本。只要Julia有一个编辑菜单,粘贴的键盘快捷方式是cmd(和大多数应用程序一样),并且您的光标被放置在合适的位置,粘贴就可以工作了。祝好运。

代码语言:javascript
复制
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放在最前面的方法。

代码语言:javascript
复制
tell application "System Events" to tell process "Julia-0.2.1" to set frontmost to true

请注意,如果这没有将Julia窗口放在最前面,那么这是因为进程名是错误的。有时进程名与应用程序名称不同。如果是的话,您必须知道Julia进程的名称,这可以通过运行这个过程并找到它的名称来完成。如果Julia在终端窗口运行,您可能不得不使用“终端”。

代码语言:javascript
复制
tell application "System Events" to return name of processes
票数 0
EN

Stack Overflow用户

发布于 2014-04-18 17:34:59

Julia无法编写脚本,因此您将无法以这种方式发送代码。你可以试试这个:

代码语言:javascript
复制
do shell script "julia -e '" & the_selection & "'"

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23152652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档