Problem with Converting NSApplescript to Scripting Bridge

  • The following is the old NSApplescript, which works to create array of mailbox paths.

    NSAppleScript *theScript = [[[NSAppleScript alloc]initWithSource:@"tell application \"Mail\"\n set localMailboxes to every mailbox\n end tell\n"]autorelease];
    NSDictionary *theError;
    NSAppleEventDescriptor *theScriptDescriptor = [theScript executeAndReturnError: &theError];
    if (theScriptDescriptor == nil) {
    } else {
        NSString *descriptorString;
        int i, u = [theScriptDescriptor numberOfItems];
        for (i = 1; i<=u; i++) {
            descriptorString = [[[theScriptDescriptor descriptorAtIndex:i]paramDescriptorForKeyword:(AEKeyword)'seld']stringValue];
            if (descriptorString == NULL) {
            } else {
                [mailboxes_File addObject:descriptorString];
            }
        }
    }

    I am trying to substitute Scripting Bridge code with some difficulty.  Iterating through containers, see the following, is slow by comparison to the foregoing NSApplescript.  The container hierarchy involved goes down 6 levels.

    -(MailMailbox *)returnTheContainer:(MailMailbox *)incoming_Container
    {
        MailMailbox *returnedContainer = [incoming_Container container];
        return returnedContainer;
    }

    SBElementArray *allMailboxes = [mailApp mailboxes];
    int countOfAllMailboxes = [allMailboxes count];
    int i;
    for (i = 0; i < countOfAllMailboxes; i++) {

        NSString *mailboxName = [[allMailboxes objectAtIndex:i]name];
        MailMailbox *returnedContainer = [[allMailboxes objectAtIndex:i]container];

        BOOL allContainersFound = NO;
        NSMutableString *returnedPathName = [NSMutableString string];
        [returnedPathName appendString:mailboxName];
        if ([returnedContainer name] == NULL) {
            allContainersFound = YES;
        } else {
            [returnedPathName insertString:@"/" atIndex:0];
            [returnedPathName insertString:[returnedContainer name] atIndex:0];
        }

        while (allContainersFound == NO) {
            returnedContainer = [self returnTheContainer:(MailMailbox *)returnedContainer];
            if ([returnedContainer name] == NULL) {
                allContainersFound = YES;
            } else {
                NSString *returnedName = [returnedContainer name];
                [returnedPathName insertString:@"/" atIndex:0];
                [returnedPathName insertString:returnedName atIndex:0];
            }
        }
        [mailboxes_File addObject:returnedPathName];
    }

    I have looked at the SBOject class and tried the the following with 'seld', which returns null (I could be using it wrong also):
    - (SBObject *) propertyWithCode:(AEKeyword)code;

    Anyone have any experience in returning the full path directly from the MailMailbox or a way of speeding this up?


    Best regards,

    John MacMullin
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today