Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Daryle Walker
On Aug 22, 2014, at 1:24 AM, Daryle Walker  wrote:

> I changed my app from implementing -application:openFile: to 
> -application:openFiles: in my application delegate. Then, I noticed that my 
> Open File menu command directly calls my window creation function, and I 
> decided to change the action handler to call -application:openFiles: instead. 
> Later I realized that changing a global via -replyToOpenOrPrint: to the 
> application object may not be a good idea if said object doesn’t expect it 
> (like outside of application launch). So now I want to re-reimplement the 
> open-file action handler by calling the open-file Apple Event to myself. 
> Looking through the modern Apple docs, I see all sorts of stuff about 
> handling Apple Events, but nothing about sending them. Help.
> 
> Oh, is there a non-retired list of the basic Apple Events and their required 
> and optional parameters?

I figured out something that (seemingly) works, but I feel slightly dirty:

> - (IBAction)openDocument:(id)sender {
> NSOpenPanel * const  panel = [NSOpenPanel openPanel];
> 
> panel.allowsMultipleSelection = YES;
> panel.delegate = self;
> [panel beginWithCompletionHandler:^(NSInteger result) {
> if (result == NSFileHandlingPanelOKButton) {
> NSAppleEventDescriptor * const   fileList = 
> [NSAppleEventDescriptor listDescriptor];
> NSAppleEventDescriptor * const  openEvent = 
> [NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass 
> eventID:kAEOpenDocuments targetDescriptor:nil returnID:kAutoGenerateReturnID 
> transactionID:kAnyTransactionID];
> 
> for (NSURL *file in panel.URLs) {
> [fileList insertDescriptor:[NSAppleEventDescriptor 
> descriptorWithDescriptorType:typeFileURL data:[[file absoluteString] 
> dataUsingEncoding:NSUTF8StringEncoding]] atIndex:0];
> }
> [openEvent setParamDescriptor:fileList 
> forKeyword:keyDirectObject];
> [[NSAppleEventManager sharedAppleEventManager] 
> dispatchRawAppleEvent:[openEvent aeDesc] withRawReply:(AppleEvent 
> *)[[NSAppleEventDescriptor nullDescriptor] aeDesc] handlerRefCon:(SRefCon)0];
> }
> }];
> }

Is this the best we can do? (BTW, “SRefCon” went from an integer to a pointer 
during the 32/64-bit transition.)

I’m writing the following down so I don’t forget if I try to access Apple’s 
Radar bug/request system.

NSAppleEventManager.h
A category on NSWorkspace
Method(s) to translate an application identifier to a target 
NSAppleEventDescriptor.
Method to send an AppleEvent, with the application already specified within, as 
the initial A.E. for the newly-launched application. Add a Boolean parameter to 
control whether to proceed if the application was already running. Maybe add a 
block that takes the reply AppleEvent (set to nil when a reply isn’t desired).
Method to translate a NSRunningApplication object to a target 
NSAppleEventDescriptor.
Method to send an AppleEvent (as a NSAppleEventDescriptor) with a block to 
accept the reply AppleEvent (or nil if undesired).
NSAppleEventDescriptor.h needs to add a method to return a target 
NSAppleDescriptor of the current application. It differs from using 
[NSRunningApplication currentApplication] in that the target value in this 
header is for shortcut dispatch while the former one is for full dispatch (like 
if an outside app sent the event).

Any improvements for this idea? I guess it’s too late for Yosemite (unless they 
had the same idea by coincidence).

Oh, add a modern AppleEvent reference. I remember from the 1990s and the 
following decade that some events added extra (optional) parameters, like for 
searching.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Mills, Steve
On Aug 22, 2014, at 12:35:53, Kyle Sluder  wrote:

> On Fri, Aug 22, 2014, at 12:10 PM, Fritz Anderson wrote:
>> On 22 Aug 2014, at 10:40 AM, Kyle Sluder  wrote:
>> 
>>> This is a very strange idea. Cocoa applications do not do this; they just 
>>> call straight into NSDocumentController.
>> 
>> Even if they want to be recordable?
> 
> I can't think of an application on my system that's recordable except
> for TextWrangler.

Which is a crying shame. Why isn't Apple building recordability into Cocoa? 
Used to be all the good apps were totally recordable.

--
Steve Mills
office: 952-818-3871
home: 952-401-6255


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Kyle Sluder
On Fri, Aug 22, 2014, at 12:10 PM, Fritz Anderson wrote:
> On 22 Aug 2014, at 10:40 AM, Kyle Sluder  wrote:
> 
> > This is a very strange idea. Cocoa applications do not do this; they just 
> > call straight into NSDocumentController.
> 
> Even if they want to be recordable?

I can't think of an application on my system that's recordable except
for TextWrangler.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Fritz Anderson
On 22 Aug 2014, at 10:40 AM, Kyle Sluder  wrote:

> This is a very strange idea. Cocoa applications do not do this; they just 
> call straight into NSDocumentController.

Even if they want to be recordable?

— F


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Kyle Sluder
On Aug 21, 2014, at 10:24 PM, Daryle Walker  wrote:
> 
> I changed my app from implementing -application:openFile: to 
> -application:openFiles: in my application delegate. Then, I noticed that my 
> Open File menu command directly calls my window creation function, and I 
> decided to change the action handler to call -application:openFiles: instead. 
> Later I realized that changing a global via -replyToOpenOrPrint: to the 
> application object may not be a good idea if said object doesn’t expect it 
> (like outside of application launch). So now I want to re-reimplement the 
> open-file action handler by calling the open-file Apple Event to myself.

This is a very strange idea. Cocoa applications do not do this; they just call 
straight into NSDocumentController.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread Jean-Daniel Dupas

Le 22 août 2014 à 07:24, Daryle Walker  a écrit :

> I changed my app from implementing -application:openFile: to 
> -application:openFiles: in my application delegate. Then, I noticed that my 
> Open File menu command directly calls my window creation function, and I 
> decided to change the action handler to call -application:openFiles: instead. 
> Later I realized that changing a global via -replyToOpenOrPrint: to the 
> application object may not be a good idea if said object doesn’t expect it 
> (like outside of application launch). So now I want to re-reimplement the 
> open-file action handler by calling the open-file Apple Event to myself. 
> Looking through the modern Apple docs, I see all sorts of stuff about 
> handling Apple Events, but nothing about sending them. Help.

I think you can use NSWorkspace. It will generate the same events than the one 
send when you try to open a file from the Finder.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-22 Thread 2551

On 22 Aug 2014, at 12:24, Daryle Walker  wrote:
> Oh, is there a non-retired list of the basic Apple Events and their required 
> and optional parameters?
> 

Non-retired? Hmm; tricky. There's Apple Event Manager Reference and Apple 
Events Programming Guide, both 2007, both marked as 'legacy'. 

Then there's NSAppleEventDescriptor Class Reference, also from 2007 and NOT 
marked as legacy (last I looked).

Phil


signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

What is the modern Cocoa way to send an Apple Event to yourself?

2014-08-21 Thread Daryle Walker
I changed my app from implementing -application:openFile: to 
-application:openFiles: in my application delegate. Then, I noticed that my 
Open File menu command directly calls my window creation function, and I 
decided to change the action handler to call -application:openFiles: instead. 
Later I realized that changing a global via -replyToOpenOrPrint: to the 
application object may not be a good idea if said object doesn’t expect it 
(like outside of application launch). So now I want to re-reimplement the 
open-file action handler by calling the open-file Apple Event to myself. 
Looking through the modern Apple docs, I see all sorts of stuff about handling 
Apple Events, but nothing about sending them. Help.

(The app doesn’t use the NSDocument architecture. In fact, I ripped that out.)

Oh, is there a non-retired list of the basic Apple Events and their required 
and optional parameters?

(If some Apple expert says calling [NSApp replyToOpenOrPrint:X] arbitrarily is 
OK, I still want to switch to Apple Events.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com