我正在尝试设置一个TextWrangler脚本,自动将选定的代码发送给朱莉娅。从执行将代码发送到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“的行。有人建议怎么解决这个问题吗?
发布于 2014-04-18 19:09:46
好吧,如果朱莉娅不是像@khagler所说的那样有剧本的话,那么你通常可以使用gui脚本。只要Julia有一个编辑菜单,粘贴的键盘快捷方式是cmd(和大多数应用程序一样),并且您的光标被放置在合适的位置,粘贴就可以工作了。祝好运。
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放在最前面的方法。
tell application "System Events" to tell process "Julia-0.2.1" to set frontmost to true请注意,如果这没有将Julia窗口放在最前面,那么这是因为进程名是错误的。有时进程名与应用程序名称不同。如果是的话,您必须知道Julia进程的名称,这可以通过运行这个过程并找到它的名称来完成。如果Julia在终端窗口运行,您可能不得不使用“终端”。
tell application "System Events" to return name of processes发布于 2014-04-18 17:34:59
Julia无法编写脚本,因此您将无法以这种方式发送代码。你可以试试这个:
do shell script "julia -e '" & the_selection & "'"这相当于在终端窗口中键入命令。根据所选内容的具体内容,您可能需要先将其保存为文件,然后才能传递文件路径。另外,请注意,如果julia不在您的路径中(就像您刚刚将朱莉娅应用程序复制到您的应用程序文件夹中那样),您将需要在.app包中指定到实际可执行文件的完整路径:/Applications/Julia-0.2.1.app/Contents/Resources/julia/bin/julia。
https://stackoverflow.com/questions/23152652
复制相似问题