5

tell application "Finder" to open POSIX file */path/to/somefilename*C++プログラムからApplescriptコマンドを実行したいのですが。使いたいようですがOSACompileExecute、使い方の例が見つかりませんでした。OSACompileターミナルコマンドの使い方の例を探し続けています。誰かが例または例へのリンクを提供できますか?

4

2 に答える 2

6

さて、トリックは、Applescriptをコンパイルして実行しようとするのではなく、単にosascriptシステムコマンドを使用することでした。

    sprintf(cmd, "osascript -e 'tell app \"Finder\" to open POSIX file \"%s/%s\"'", getcwd(path, MAXPATHLEN), file);
    system(cmd);

pathfileは両方ともchar[]変数です。

私はApplescriptからのこの抜粋から手がかりを得ました:決定的なガイド。

于 2012-02-01T20:16:53.460 に答える
1

これは、AppleScriptを使用してファインダーからGetInfoコメントを読み取るためのC関数の例です。

必要に応じて変更できます。

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;
于 2012-02-01T19:28:49.637 に答える