如何从 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
和 file
都是 char[] 变量.
path
and file
are both char[] variables.
我从 这段摘录来自Applescript:权威指南.
这篇关于如何从 C++ 程序执行一个简单的 Applescript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!