我想從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