Another Weird AppleScript-ObjC Problem
Another Weird AppleScript-ObjC Problem
- Subject: Another Weird AppleScript-ObjC Problem
- From: Dave <email@hidden>
- Date: Mon, 16 Nov 2015 13:46:40 +0000
Hi,
I have a handler in a .applescript file (getOutlookPropertiesDictionaryWithWindowID ) that is called from Objective-C and from also from another Handler in the save Script. Please see below:
on getOutlookPropertiesDictionaryWithWindowID:(theWindowID as string)
say "getOutlookPropertiesDictionaryWithWindowID:" & theWindowID
set myWindowID to theWindowID as number
set myMessageDictionary to my newOutlookMessageDictionary()
tell application "Microsoft Outlook"
say "Debug 1"
set myWindow to (get window id myWindowID)
set myWindowObject to the object of myWindow
set myWindowClass to the class of myWindowObject as string
set myWindowName to the name of myWindow
say "Debug 2"
set myMessageID to id of myWindowObject
set myMessage to (get message id myMessageID)
say "Debug 3"
--
-- Get a New Recipient Dictionary
--
set myRecipientDictionary to my newOutlookRecipientDictionaryWithMessageID:(myMessageID)
say "Debug 4"
--
-- Get a New Attachments Array
--
set myAttachmentsArray to my newOutlookAttachmentsArrayWithMessageID:(myMessageID)
say "Debug 5"
--
-- Set Up the Message Properties Dictionary
--
set kMessageID of myMessageDictionary to (the id of myMessage as string)
set kMessageClass of myMessageDictionary to my getOutlookClassStringWithClass:(the class of myMessage)
set kMessageWindowID of myMessageDictionary to (theWindowID as string)
set kMessageWindowClass of myMessageDictionary to my getOutlookClassStringWithClass:(the class of myWindow)
set kMessageWindowName of myMessageDictionary to (myWindowName as string)
say "Debug 6"
set kMessageSubject of myMessageDictionary to the subject of myMessage
set kMessagePlainContent of myMessageDictionary to the plain text content of myMessage
set kMessageHTMLContent of myMessageDictionary to the content of myMessage
say "Debug 7"
set kMessagePriority of myMessageDictionary to my getOutlookPriorityString:(the priority of myMessage)
set kMessageRecipientDictionary of myMessageDictionary to myRecipientDictionary
set kMessageAttachmentArray of myMessageDictionary to myAttachmentsArray
say "Debug 8"
end tell
say "Debug 9"
return myMessageDictionary as record
end getOutlookPropertiesDictionaryWithWindowID:
on setOutlookPropertiesDictionary:(theMessageDictionary as record)
say "setOutlookPropertiesDictionary:"
set myWindowID to kMessageWindowID of theMessageDictionary as number
set myMessageID to kMessageID of theMessageDictionary
tell application "Microsoft Outlook"
say "Debug 1"
set myWindow to (get window id myWindowID)
set myMessage to (get message id myMessageID)
say "Debug 2"
set the subject of myMessage to kMessageSubject of theMessageDictionary
set the plain text content of myMessage to kMessagePlainContent of theMessageDictionary
set the content of myMessage to kMessageHTMLContent of theMessageDictionary
say "Debug 3"
set myRepipientDictionary to kMessageRecipientDictionary of theMessageDictionary
get my replaceOutlookMessageRecipientArrayWithMessageID:(myMessageID) andRecipientDictionary:(myRepipientDictionary)
say "Debug 4"
set myAttachmentsArray to kMessageAttachmentArray of theMessageDictionary
get my replaceOutlookMessageAttachmentsArrayWithMessageID:(myMessageID) andAttachmentArray:(myAttachmentsArray)
say "Debug 5"
close myWindow without saving
open message id myMessageID
say "Debug 6"
set myWindowID to my getOutlookFrontWindowID() as number
set myMessageDictionary to my getOutlookPropertiesDictionaryWithWindowID:(myWindowID)
end tell
if myMessageDictionary = missing value then
say "myMessageDictionary Missing Value"
end if
set myMessageID to kMessageID of myMessageDictionary
say "Debug 7 myMessageID: " & myMessageID
return myMessageDictionary as record
end setOutlookPropertiesDictionary:
When I call getOutlookPropertiesDictionaryWithWindowID from Objective-C I get the dictionary return ok as expected, however, when I call it from setOutlookPropertiesDictionary it appears to return ok from getOutlookPropertiesDictionaryWithWindowID, but when setOutlookPropertiesDictionary returns to Objective-C the dictionary is nil?
Here is the Calling Objective-C code, it’s called via a Button Click for Testing.
-(IBAction) preformTest:(id) theSender
{
NSMutableDictionary* myMessageDictionary;
NSMutableArray* myMessageAttachmentsArray;
NSString* myWindowID;
NSMutableDictionary* myRecipientDictionary;
NSMutableArray* myRecipientsArray;
myWindowID = [self.pSingletonManager.pOfficeAppleScriptManager outlookGetFrontWindowID];
myMessageDictionary = [[self.pSingletonManager.pOfficeAppleScriptManager outlookGetPropertiesDictionaryWithWindowID:myWindowID] mutableCopy];
LogIfDave(@"myMessageDictionary:\n%@",myMessageDictionary);
[myMessageDictionary setObject:@"OBJ-C BRAVE NEW SUBJECT" forKey:kMessageSubject];
[myMessageDictionary setObject:@"OBJ-C BRAVE NEW PLAIN CONTENT" forKey:kMessagePlainContent];
[myMessageDictionary setObject:@"OBJ-C BRAVE NEW HTML CONTENT" forKey:kMessageHTMLContent];
myRecipientDictionary = [[myMessageDictionary objectForKey:kMessageRecipientDictionary] mutableCopy];
myRecipientsArray = [[myRecipientDictionary objectForKey:@"BJDocPropToRecipsSMTPAddress"] mutableCopy];
[myRecipientsArray addObject:@"email@hidden"];
[myRecipientsArray addObject:@"email@hidden"];
[myRecipientsArray addObject:@"email@hidden"];
[myRecipientDictionary setObject:myRecipientsArray forKey:@"BJDocPropToRecipsSMTPAddress"];
[myMessageDictionary setObject:myRecipientDictionary forKey:kMessageRecipientDictionary];
myMessageAttachmentsArray = [[NSMutableArray alloc] init];
[myMessageAttachmentsArray addObject:@"/Documents/DocProperties/Sample1.docx"];
[myMessageAttachmentsArray addObject:@"/Documents/DocProperties/Sample2.docx"];
[myMessageAttachmentsArray addObject:@"/Documents/DocProperties/Sample3.docx"];
[myMessageDictionary setObject:myMessageAttachmentsArray forKey:kMessageAttachmentArray];
LogIfDave(@"Before Set - myMessageDictionary:\n%@",myMessageDictionary);
myMessageDictionary = [[self.pSingletonManager.pOfficeAppleScriptManager outlookSetPropertiesDictionary:myMessageDictionary] mutableCopy];
//myMessageDictionary == nil at this point……….
LogIfDave(@"After Set - myMessageDictionary:\n%@",myMessageDictionary);
return;
}
So close, yet so far away………. Does anyone have any idea on how to make this work.
Also, having Script Editor as an External Editor is causing much grief because of constant crashes when I compile scripts. I can open the .applescript file using “Open with External Editor” then simply add a comment line and press compile which will result in an instant crash. I edit the same file with XCode and then open it with Script Editor it nearly always compiles ok, but a couple of times I’ve had a script that would crash Script Editor and there seemed like nothing would stop it crashing until I pasted the whole of the contents and saved it to another .applescript file, removed the old one and renamed and then it worked????? I tried using smile, but then XCode wouldn’t compile the file. Is there another more reliable AS editor that I can use for this?
Seems like everything about AppleScript has some kind of problems associated with it and there is no clean, reliable way of interfacing between Objective-C and AppleScript, the Scripting Bridge is broken too…………………..
Thanks a lot,
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