如何从C ++程序执行一个简单的AppleScript? [英] How can I execute a simple Applescript from a C++ program?
问题描述
我想执行AppleScript的命令告诉应用程序发现者打开POSIX文件* /路径/要/ somefilename *
从C ++程序。它看起来像我可能要使用 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);
路径
和文件
都是的char []变量。
path
and file
are both char[] variables.
我接到线索<一个href=\"http://www.myths.com/pub/doc/oh_really/other/AppleScript_The_Definitive_Guide/0596005571_applescpttdg-chp-23-sect-2.html\"相对=nofollow>从的AppleScript此摘录:权威指南的
I got the clue from this excerpt from Applescript: The Definitive Guide.
这篇关于如何从C ++程序执行一个简单的AppleScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!