Re: Scripting Bridge Question
Re: Scripting Bridge Question
- Subject: Re: Scripting Bridge Question
- From: Christopher Nebel <email@hidden>
- Date: Tue, 27 Oct 2015 12:53:47 -0700
Short answer: See the additional methods defined by SBElementArray, in particular -objectWithID:. Based on the rest of your Objective-C code, you probably want this:
myOutgoingMessage = [myOutgoingMessageArray objectWithID:@(myDraftObjectID)];
…though that’s not quite what your original script did. (The “@(...)” is necessary because -objectWithID: takes an object, not a bare NSInteger.) Longer answer available if you need it, but also see <https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/UsingScriptingBridge/UsingScriptingBridge.html#//apple_ref/doc/uid/TP40006104-CH4-SW12>.
—Chris Nebel
Automation Engineering
> On Oct 26, 2015, at 4:20 AM, Dave <email@hidden> wrote:
>
> Hi,
>
> I’m using the Scripting Bridge to Target MS Outlook. I’m trying to figure out how to do the following AppleScript using the Scripting Bridge. Please see Full Script below, I’ve got most of the code, but I can’t seem to figure out the right Objective-C code for these two statements:
>
> set myObjectID to the id of (object of myWindow)
> set myContent to the plain text content of message id myObjectID
>
> on run
> tell application id "com.microsoft.Outlook"
> activate
> set myWindow to the front window
> if class of myWindow is not draft window then
> return "Error - Not Draft Window"
> end if
>
> set myObjectID to the id of (object of myWindow)
> set myContent to the plain text content of message id myObjectID
>
> return myContent
> end tell
> end run
>
>
> I have the following Objective-C code:
>
> -(BOOL) outlookGetDraftWindowForWindowIndex:(NSInteger) theWindowIndex returnDraftWindow:(SXOutlook2011DraftWindow**) theDraftWindowPtr returnMessage:(SXOutlook2011OutgoingMessage**) theOutgoingMessagePtr
> {
> SXOutlook2011Application* myOutlookApp;
> SBElementArray* myOutgoingMessageArray;
> SBElementArray* myDraftWindowsArray;
> SXOutlook2011DraftWindow* myDraftWindow;
> SXOutlook2011OutgoingMessage* myOutgoingMessage;
> SXOutlook2011Object* myDraftObject;
> NSInteger myDraftObjectID;
>
> //**
> //** Get the Outlook Application
> //**
> myOutlookApp = [self.pSingletonManager.pScriptingBridgeManager getHandlerWithAppInternalID:kBundleIDOutlook];
> if (myOutlookApp == nil)
> return NO;
>
> if (theDraftWindowPtr != NULL)
> *theDraftWindowPtr = nil;
>
> if (theOutgoingMessagePtr != NULL)
> *theOutgoingMessagePtr = nil;
>
> myOutgoingMessageArray = [myOutlookApp outgoingMessages];
> myDraftWindowsArray = [myOutlookApp draftWindows];
> if ([myDraftWindowsArray count] < theWindowIndex)
> return NO;
>
> myDraftWindow = [myDraftWindowsArray objectAtIndex:theWindowIndex];
> if ([myDraftWindow exists] == NO)
> return NO;
>
> //**
> //** Save the Window before Getting the Message
> //**
> [myDraftWindow saveIn:nil as:myDraftWindow.name];
>
> myDraftObject = myDraftWindow.object;
> if ([myDraftWindow exists] == NO)
> return NO;
>
> myDraftObjectID = myDraftObject.id;
> myOutgoingMessage = [self findMessageWithID:myDraftObjectID inArray:myOutgoingMessageArray];
>
> if (theDraftWindowPtr != NULL)
> *theDraftWindowPtr = myDraftWindow;
>
> if (theOutgoingMessagePtr != NULL)
> *theOutgoingMessagePtr = myOutgoingMessage;
>
> return YES;
> }
>
>
> Which works but takes for ever because:
>
> myOutgoingMessage = [self findMessageWithID:myDraftObjectID inArray:myOutgoingMessageArray];
>
> Does a sequential search of the Outgoing Message array, which is ok if there are only a few messages but as soon as you get more than about 100 it takes way too long.
>
> Any ideas on this would be greatly appreciated.
>
> All the Best
> Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden