如何从一个C ++程序执行一个简单的Applescript? [英] How can I execute a simple Applescript from a C++ program?
问题描述
我想执行Applescript命令告诉应用程序Finder从C ++程序打开POSIX文件* / path / to / somefilename *
。看起来我可能想使用 OSACompileExecute
,但我还没有能够找到一个如何使用它的例子。我继续找到如何使用 OSACompile
终端命令的示例。有人可以提供一个例子或一个链接到一个例子吗?
I would like to execute the Applescript command tell application "Finder" to open POSIX file */path/to/somefilename*
from a C++ program. It looks like I might want to use OSACompileExecute
, but I haven't been able to find an example of how to use it. I keep finding examples of how to use the OSACompile
Terminal command. Can someone provide an example or a link to an example?
推荐答案
好吧,诀窍是不打扰试图编译和执行Applescript,但只需使用 osascript
系统命令:
Ok, the trick was to not bother trying to compile and execute the Applescript but to simply use the osascript
system command:
sprintf(cmd, "osascript -e 'tell app \"Finder\" to open POSIX file \"%s/%s\"'", getcwd(path, MAXPATHLEN), file);
system(cmd);
path
文件都是char []变量。
path
and file
are both char[] variables.
I got the clue from this excerpt from Applescript: The Definitive Guide.
这篇关于如何从一个C ++程序执行一个简单的Applescript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!