3

だから私は次のように私のプログラムの機能の1つを実行しているAppleスクリプトを持っています:

[ NSThread detachNewThreadSelector:@selector(runAppleScriptTask)
                          toTarget:self
                        withObject:nil];

この方法の使用:

-(void)runAppleScriptTask
{
    mainBundle = [NSBundle bundleForClass:[self class]];
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSDictionary* errorDict;
    NSAppleEventDescriptor* returnDescriptor = NULL;
    NSString *scriptPath = [[NSBundle mainBundle] pathForResource: @"AttemptToRepair"
                                                           ofType: @"scpt"];

    NSLog(@"Found AppleScript Path:%@",scriptPath);

    // Run the Apple Script
    NSAppleScript *scriptObject = [[NSAppleScript alloc]initWithContentsOfURL:[NSURL fileURLWithPath: scriptPath]
                                                                        error:&errorDict];
    returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
    NSLog(@"Return Discriptor,%@",returnDescriptor);

    NSString *returnValue = @"User Canceled";
    NSMutableDictionary *returnDict  = [[NSMutableDictionary alloc] init];

    if ([ returnDescriptor stringValue]) {
        returnValue = [ returnDescriptor stringValue];
        [ returnDict setValue:returnValue forKey:@"returnValue"];
    }
    else {
        if (errorDict) {
            returnValue = [ returnDescriptor stringValue];
            [ returnDict setValue:errorDict forKey:@"errorDict"];
        }
    }





    NSLog(@"Found Return Value: %@",returnValue);

    [scriptObject release];

    // Notify 
    [[NSNotificationCenter defaultCenter]
     postNotificationName:AttemptToRepairCompleteNotification
     object:self
     userInfo:returnDict];
    [pool drain];
}

Apple Script に渡す必要があるNSArray(Full of Statuses) があります。現在、ファイルを plist にダンプしています。

// File Drop the Global Status Array
BOOL gsaWroteSuccess = [ issueFile writeToFile:@"/private/tmp/gsa.plist" atomically:YES];
if (gsaWroteSuccess) {
    NSLog(@"Wrote the current Global Status Array to file");

    // Let objects know the Global Status is being updated
    NSMutableDictionary *globalStatusUpdate = [[NSMutableDictionary alloc] init];
    // Pass the mutated Data to our NSTable
    [ globalStatusUpdate setValue:issueFile forKey:@"globalStatusArray"];
    [[NSNotificationCenter defaultCenter]
     postNotificationName:StatusUpdateNotification
     object:self
     userInfo:globalStatusUpdate];
}
else {
    NSLog(@"Unable to write Global Status Array to file");
}

これは、 System Events plist infrastructure を介して Apple Script で簡単に取得できますが、実際にはこれをすべて RAM で行うことをお勧めします。ここで言及されているプロパティ構文を使用できると思いますhttp://developer.apple.com/library/mac/#releasenotes/ScriptingAutomation/RN-AppleScriptObjC/_index.htmlしかし、10.5、10.6、および10.7で動作するにはこれが必要ですそのため、まだリリースされていないものは使用できません。NSArray完全なオブジェクトまたはNSDicitonaryオブジェクトを Apple Script (Apple Script のリストになります)に渡すためのメモリベースの滑らかな方法についての考えはありますか?

これが役立つ場合、ファイルドロップ方法論のApple Scriptコードです

script AttemptToRepair
    property parent : class "NSObject"
    activate
    set thePListPath to POSIX path of "/tmp/gsa.plist"
    tell application "System Events"

        set the plist_path to "/tmp/gsa.plist"
        set the plist_file to property list file plist_path

        set itemNodes to property list items of property list item "globalStatusArray" of plist_file


        repeat with i from 1 to number of items in itemNodes

            set itemNode to item i of itemNodes

            set discription to value of property list item "discription" of itemNode
            set metric to value of property list item "metric" of itemNode
            set reason to value of property list item "reason" of itemNode
            set status to value of property list item "status" of itemNode
            display dialog "discription:" & discription & return & ¬
                "metric:" & metric & return & ¬
                "reason:" & reason & return & ¬
                "status:" & status
        end repeat

    end tell
end script
run AttemptToRepair
4

0 に答える 0