从SublimateText运行AppleScript时出现问题

从SublimateText运行AppleScript时出现问题,applescript,sublimetext2,stata,sublimetext3,Applescript,Sublimetext2,Stata,Sublimetext3,我被卡住了。我有一个SublimiteText插件,我在Stata(一个统计软件包)中编写了运行代码。 准备好文件后,我通常会这样做: cmd = """osascript<< END tell application "stata" activate open POSIX file "%s" end tell END""" % dofile_path os.system(cmd) 我也尝试过这样的多行脚本 cmd = """osascript<< END

我被卡住了。我有一个SublimiteText插件,我在Stata(一个统计软件包)中编写了运行代码。 准备好文件后,我通常会这样做:

cmd = """osascript<< END
 tell application "stata" 
  activate
  open POSIX file "%s"
 end tell
END""" % dofile_path
os.system(cmd)
我也尝试过这样的多行脚本

cmd = """osascript<< END
tell application \"StataMP\"
    activate
end tell
tell application \"System Events\"
    keystroke \"1\" using {command down}
    set the clipboard to \"do %s\"
    keystroke \"v\" using {command down}
    keystroke return
end tell
say "finished"
END""" % dofile_path
os.system(cmd)

cmd=”““osascript在获得Stata 13后,我的BBEdit脚本在运行do文件时遇到了同样的问题。下面是现在可以使用的方法;也许您可以将其改编为ST。诀窍是使用
docomand
脚本命令从Stata内部执行do文件。脚本将在没有
docomand的情况下工作。”cd
行,但该行确保程序日志和数据文件与do文件保存在同一文件夹中

tell application "BBEdit"
    save text document 1
    set loc to file of text document 1 as alias
end tell


tell application "StataMP"
    activate
    if version < 13 then
        open loc
    else
        tell application "Finder"
            set foldr to POSIX path of (folder of file loc as alias)
            set ploc to the POSIX path of loc
        end tell
        DoCommand "cd " & "\"" & foldr & "\""
        DoCommand "do " & "\"" & ploc & "\""
    end if
end tell
告诉应用程序“BBEdit”
保存文本文档1
将loc设置为文本文档1的文件作为别名
结束语
告诉应用程序“StataMP”
激活
如果版本<13,则
开放loc
其他的
告诉应用程序“查找器”
将foldr设置为的POSIX路径(文件loc的文件夹作为别名)
将ploc设置为loc的POSIX路径
结束语
DoCommand“cd”和“foldr”
DoCommand“do”和“ploc”
如果结束
结束语

所以我似乎已经解决了这个问题,但几乎完全是偶然的。 首先,您必须转到“首选项”>“Do文件编辑器”>“高级”,并取消选中“编辑从Do文件编辑器中的查找程序打开的Do文件”框。但这还不够。我还更改了applescript,使其与Finder而不是Stata对话

cmd = """osascript<< END
tell application "Finder"
  open POSIX file "%s"
end tell
END""" % dofile_path

cmd=”“”OSAScript谢谢。不幸的是,我仍然在Stata 12上,它没有实现AppleScript DoCommand:(值得注意的是,对于任何阅读本文的人,Andrew Heiss已经为此实现了一个。我现在将继续使用Stata 12!太糟糕了。我的脚本确实将
open loc
命令(我在您的原始脚本中看到)应用于版本伟大的发现!我从来没有想过要查看这些版本,因为我很少使用编辑器。事实证明,我如果首选项更改,我仍然可以
告诉Stata打开loc
。唯一的行为更改是do文件暂停,除非我
设置了更多设置
。当我运行发布的版本时,这不是不必要的。
cmd = """osascript<< END
tell application "Finder"
  open POSIX file "%s"
end tell
END""" % dofile_path