如何从一个C ++程序执行一个简单的Applescript? [英] How can I execute a simple Applescript from a C++ program?

查看:200
本文介绍了如何从一个C ++程序执行一个简单的Applescript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆