我想从C++程序执行Applescript命令tell application "Finder" to open POSIX file */path/to/somefilename*
。它看起来像我可能想要使用OSACompileExecute
,但我一直无法找到如何使用它的例子。我一直在找到如何使用OSACompile
终端命令的例子。有人可以提供一个例子或一个例子的链接?如何从C++程序执行简单的Applescript?
3
A
回答
4
好,诀窍是白费力气试图编译和执行的AppleScript,而是简单地使用osascript
系统命令:
sprintf(cmd, "osascript -e 'tell app \"Finder\" to open POSIX file \"%s/%s\"'", getcwd(path, MAXPATHLEN), file);
system(cmd);
path
和file
都的char []变量。
我从this excerpt从得知线索:权威指南。
1
下面是一个示例C函数,用于使用AppleScript从查找器读取Get Info注释。
您可以根据需要对其进行修改。
NSString * readFinderCommentsForFile(NSString * theFile){
/* Need to use AppleScript to read or write Finder Get Info Comments */
/* Convert POSIX file path to hfs path */
NSURL * urlWithPOSIXPath = [NSURL fileURLWithPath:theFile];
NSString * hfsStylePathString =
(__bridge_transfer NSString *)CFURLCopyFileSystemPath((__bridge CFURLRef) urlWithPOSIXPath, kCFURLHFSPathStyle);
/* Build an AppleScript string */
NSString *appleScriptString = @"tell application \"Finder\"\r get comment of file ";
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:hfsStylePathString];
appleScriptString = [appleScriptString stringByAppendingString:@"\""];
appleScriptString = [appleScriptString stringByAppendingString:@"\r end tell\r"];
NSString *finderComment;
NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptString];
NSDictionary *theError = nil;
finderComment = [[theScript executeAndReturnError: &theError] stringValue];
NSLog(@"Finder comment is %@.\n", finderComment);
return finderComment;
相关问题
- 1. 如何从C++程序执行c#exe
- 2. 如何从AppleScript制作可执行程序
- 3. 在Cocoa应用程序中定义和执行简单的AppleScript命令
- 4. 简单的Perl程序未能执行
- 5. 我应该如何从C#执行简单的oracle查询?
- 6. 如何从php执行一个applescript
- 7. 从PHP执行C程序
- 8. 从C#程序执行BatchFile
- 9. 如何通过MATLAB执行一个简单的Java程序?
- 10. 从C程序中执行程序
- 11. 从python程序执行c程序
- 12. Chrome扩展程序 - 从弹出窗口执行简单的JavaScript
- 13. 简单程序不能在c中执行
- 14. 从AppleScript执行Sikuli脚本
- 15. AppleScript:如何启动应用程序,然后执行菜单命令
- 16. 如何在Cloud9 IDE中运行简单的C++程序?
- 17. 如何在Eclipse IDE中运行简单的C程序
- 18. 如何从简单的C程序中清除屏幕?
- 19. C程序:简单的数学程序
- 20. 如何从简单的ES6应用程序进行Http操作
- 21. 如何从C++程序执行命令行命令
- 22. 如何使用C#中的cookie执行简单的GET请求#
- 23. 如何暂停执行C#.NET程序?
- 24. 从Cocoa应用程序运行AppleScript
- 25. 简单结构程序C
- 26. 从C#中的表单执行程序+参数#
- 27. 使可可应用程序响应简单的AppleScript命令
- 28. 从Java执行AppleScript的最佳方法
- 29. 从C#执行excel应用程序
- 30. C#程序将不会从Java执行
对我来说看起来不像C ... – JustSid 2012-02-01 19:35:40
它是使用NSAppleScript对象的Objective-C代码示例,不能在C++中使用 – 2012-02-01 19:40:12
对于此项目,我希望避免使用Cocoa和Objective-C if可能。 – SSteve 2012-02-01 19:40:41