Using kApplicationBundleID ('bund') with AESend

Hey all,

I hope Apple Event questions are OK here. As usual, this is so simple that of course I have been struggling with it for 2 days now.

All I want to do is send the Quit Apple Event to iSync, from C code. I’m doing this to learn and to make an automatic sync for a USB connected phone, so I already have the code to get notifications when the phone is plugged in and that works fine.

This is just a simple C app to make an Apple Event and send it to iSync. When I trace through it, it returns error -600 “procNotFound”, which means that the Application address I am sending isn’t correct. As per the Panther Tech Note, I am using the recommended kApplicationBundleID constant and passing 4 for the length, but I don’t think that is correct.

Please take a look and tell me why the AESend function can’t find the app “iSync” (I suspect that the application address isn’t in the AEDesc properly).

[code]#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
int main(int argc, char *argv[])
{
OSErr err;
char *iSyncBundleID = “com.apple.isync”;
AppleEvent doSyncEvent;
AEAddressDesc iSyncAddress;

err = AECreateDesc(typeApplicationBundleID,
				   &iSyncBundleID,
				   sizeof(iSyncBundleID),
				   &iSyncAddress);


		err = AECreateAppleEvent(
						kCoreEventClass,
						kAEQuitApplication,
						&iSyncAddress,
						kAutoGenerateReturnID,
						kAnyTransactionID,
						&doSyncEvent);

		err = AESend(
					 &doSyncEvent,
					 NULL,       
					 kAENoReply | kAECanInteract,
					 kAENormalPriority,
					 kAEDefaultTimeout,
					 NULL,           
					 NULL);          
		
	
    err = AEDisposeDesc(&doSyncEvent);

    return  err;

}[/code]
All this should do is send a Quit to iSync. The error I get is that AESend can’t find the target. The target address should be in the iSyncAddress descriptor, and from there put into the Apple Event doSyncEvent.

Thanks in advance.

Johnny

You’re correct: it’s incorrect.

err = AECreateDesc(typeApplicationBundleID, iSyncBundleID, strlen(iSyncBundleID), &iSyncAddress);
BTW, if you’re using ObjC at all, check out objc-appscript which provides a high-level ObjC wrapper around the low-level Apple Event Manager API.

You might also want to subscribe to the AppleScript-implementors mailing list.

HTH

Thanks so much! What a boneheaded mistake I made there. Re-reading the documentation it is obvious that it needs the data length. I fixed it and it works fine.

Also, the links to the other list and reference are much appreciated.

I’m about to add the AE to make iSync do a sync, and I anticipate running into some issues, namely

  1. how to handle knowing when it is done with the sync (asking it for status repeatedly versus some more elegant method - I assume that the event itself returns when iSync receives the event, not when it finishes the task)

  2. Whether sending a ‘SYNC’ event to com.apple.isync when iSync isn’t running will launch it, or whether I need to have the Finder launch it first (can non-running apps receive AEs?)

  3. There is an Event Manager flag somewhere to tell it to not bring the app to the foreground. Maybe that is the same as telling it not to allow user interaction; I’m not sure.

Anyway, thanks again. This is now fun again!

Never scripted iSync myself so no idea how it works. It’s a general scripting question though, so try posting it in a separate thread and hopefully someone else can answer it.

Apple events work on existing processes only. To launch an application, use LSLaunchApplication or similar. (e.g. There’s code for this in appscript, although it uses the older LaunchApplication function for 10.3 compatibility.)

Send mode flags are listed here:

http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/c/tdef/AESendMode

HTH