Comment puis-je exécuter un simple Applescript à partir d’un programme C ++?

Je voudrais exécuter la commande Applescript tell application "Finder" to open POSIX file */path/to/somefilename* partir d’un programme C ++. Il semblerait que je veuille utiliser OSAComstackExecute , mais je n’ai pas réussi à trouver un exemple d’utilisation. Je continue à trouver des exemples d’utilisation de la commande OSAComstack Terminal. Quelqu’un peut-il fournir un exemple ou un lien vers un exemple?

Ok, le truc était de ne pas essayer de comstackr et d’exécuter Applescript, mais simplement d’utiliser la commande système osascript :

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

path et file sont tous deux des variables char [].

J’ai eu l’idée de cet extrait de Applescript: The Definitive Guide .

Voici un exemple de fonction C permettant de lire un commentaire Get Info à partir du viseur à l’aide de AppleScript.

Vous pouvez le modifier pour ce que vous voulez.

 NSSsortingng * readFinderCommentsForFile(NSSsortingng * 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]; NSSsortingng * hfsStylePathSsortingng = (__bridge_transfer NSSsortingng *)CFURLCopyFileSystemPath((__bridge CFURLRef) urlWithPOSIXPath, kCFURLHFSPathStyle); /* Build an AppleScript ssortingng */ NSSsortingng *appleScriptSsortingng = @"tell application \"Finder\"\r get comment of file "; appleScriptSsortingng = [appleScriptSsortingng ssortingngByAppendingSsortingng:@"\""]; appleScriptSsortingng = [appleScriptSsortingng ssortingngByAppendingSsortingng:hfsStylePathSsortingng]; appleScriptSsortingng = [appleScriptSsortingng ssortingngByAppendingSsortingng:@"\""]; appleScriptSsortingng = [appleScriptSsortingng ssortingngByAppendingSsortingng:@"\r end tell\r"]; NSSsortingng *finderComment; NSAppleScript *theScript = [[NSAppleScript alloc] initWithSource:appleScriptSsortingng]; NSDictionary *theError = nil; finderComment = [[theScript executeAndReturnError: &theError] ssortingngValue]; NSLog(@"Finder comment is %@.\n", finderComment); return finderComment;