In need of AppleEvent clarity

I’m a film editor and long-time RB/Xojo user who writes apps that help other film editors. I’ve nearly completed a Xojo app that uses the HandleAppleEvent event to facilitate communication with Final Cut Pro X. Apple has published a six step procedure to do so (https://developer.apple.com/library/archive/documentation/FinalCutProX/Conceptual/FinalCutProXWorkflowsGuide/Exporting/Exporting.html#//apple_ref/doc/uid/TP40013781-CH3-SW21). The instructions are in the “Interaction Through Apple Events” section. If you successfully complete all six steps you win a prize from FCPX which is the XML file my app needs. I’ve been stuck on step 1 for several days. In step 1, FCPX sends an AE that describes an “asset” class object it’s preparing to send you, I receive the AE just fine and it appears to contain exactly what the instructions described. In turn, my app is supposed to do the following:

“The application is expected to create a placeholder asset object that represents the output of the share operation and to return an object specifier that Final Cut Pro X uses to reference the asset object in subsequent Apple events.”

The object specifier needs to contain an asset ID string and a document name. I have been unable to figure out how to create the “asset” object or return an object specifier of it. I’ve included the FCP .sdef dictionary which describes the “asset” class in my app, but I’m really stumped as to how to create one in Xojo. A big question I have is can this even be one with AppleEvents in Xojo or will I need to use AppleScript or some combination of both. I have MBS plugins, btw.

Any help getting unstuck is greatly appreciated. You can probably tell I have limited programming expertise… but I am a pretty good film editor :slight_smile:

P.S. Paul Lefebvre at Xojo kindly helped me post this project on the Hire a Developer board but I haven’t gotten any responses.

Many thanks.

Thomas Tempelmann has an AppleScript framework for Xojo at http://www.tempel.org/RB/AppleEvents. Perhaps this can help. You can also contact him for help as soon as he is back from his holiday.

Thank you , Beatrix. I have looked at Thomas’s AppleEvent Framework and am unsure if it will work for this application - due only to my limited understanding and not any lack of the framework’s capabilities. I keep going back to the question of whether what my app needs to do can be accomplished using AEs or not? If AEs can do the trick, then I think I can get there with some guidance from all of you that are so far ahead of me on this.
Many thanks, again and I look forward to emailing with Thomas sometime. I’ve followed yours and his posts for a long time.
Best.
Tony
P.S. Did I mention that this is actually the very last function needed to complete my app? The front end and back end are completely finished. It just needs this AE connection to be complete.

Can you describe in more detail what you want to do?

Hi Thomas
It might help if you explain in more detail exactly what you are trying tom achieve, rather than focussing on using a particular solution. While I am not skilled enough to help yo, I know that others on the forum may well are able to put their minds to a solution if you can explain in more detail what you are trying to achieve. Are you trying to export from Final Cut Pro to your app, export from your app to FCP, or both?

What is the used macOS version ?

Emile Schwarz asks:
What is the used macOS version ?

Hello Emile. The latest OS I’m running is Mohave 10.14.5. Before FCPX sends the first AppleEvent to my app the new security dialog “Final Cut Pro.app wants access to control my app…” is displayed. When I say “OK” my app starts receiving AE’s from FCPX. I hope this means I’ve cleared the Mohave AppleScript hurdle.

[quote]Beatrix Willius and Emile Schwarz ask:
Can you describe in more detail what you want to do?[/quote]

Yes. The goal is to receive an XML file from FCPX, or I should say, make FCPX create the requested XML file and save it to the location pointed to by my app. So far, I’ve been able to complete the necessary setups in FCPX that allow AE communication with my app. As far as I know, FCPX provides no method other than AE’s for communication with external apps. Here’s the code in my ‘HandleAppleEvent’ event:

[code]dim s, t as String

dim ae as AppleEvent = theEvent
s = ae.PrintDesc
t = ae.PrintDesc(True)

if StrComp (eventID, “crel”, 0) = 0 then
dim specifier1 as new AppleEventObjectSpecifier

end if[/code]

I’ve included the FCPX .sdef file in my Xojo project. It is documented here:

https://developer.apple.com/library/archive/documentation/FinalCutProX/Conceptual/FinalCutProXWorkflowsGuide/ScriptingDefinitionExample/ScriptingDefinitionExample.html#//apple_ref/doc/uid/TP40013781-CH5-SW1

The process of requesting an XML from FCPX starts this way, when you select my app as the target from FCPX’s ‘Share’ menu, FCPX begins the process of making the requested XML file and communicating with my app. This triggers the Mohave security dialog in my app as described in my reply to Emile. After clicking ‘OK’ in the security dialog window, FCPX sends the first AE to my app. It’s a ‘rapp’ command which launches my app if it isn’t already running. That all works fine. The second AE FCPX sends is a ‘crel’ (make) command which contains information very similar to the example in the Apple documentation found here.

https://developer.apple.com/library/archive/documentation/FinalCutProX/Conceptual/FinalCutProXWorkflowsGuide/AppleScriptExample/AppleScriptExample.html#//apple_ref/doc/uid/TP40013781-CH6-SW1

Listing 5.1 is an AppleScript representation of the information in the ‘crel’ AE. Listing 5.2 is an AppleScript representation of the entire process of sending the XML file to an external app.

Using the Xojo ‘PrintDesc()’ function found in the 'Advanced AppleEvents section, the ‘crel’ AE from FCPX contains the following data:

My understanding of the above script is that FCPX wants my app to create a new object of the class ‘asset’ as a placeholder for the data to come later in the process., It should include the name property “Wooded_Path_System_Cue_07_v6B” and the other metadata elements that are specified. This is where I’m stuck. I don’t know how to create the new object ‘asset’ which includes the required data or send it back to FCPX.

Here’s the set-by-step instructions found in the ‘Interaction Through Apple Events’ section. This interaction I’ve described is the first in the process.

https://developer.apple.com/library/archive/documentation/FinalCutProX/Conceptual/FinalCutProXWorkflowsGuide/Exporting/Exporting.html#//apple_ref/doc/uid/TP40013781-CH3-SW21

My understanding at the present is that my app needs to return an object specifier for the newly created ‘asset’ object to FCPX in order to precede to the next step. I’ve tried to use the ae.ReturnObject.Specifier property but don’t fully understand how it works or how to make the ‘asset’ object in the first place. The Xojo documentation makes it sound like the reply is returned automatically. If so, how is it sent? As part of the original AE? Or do you need to actually ‘send’ the original AE containing the newly made object specifier back to FCPX? I’m completely stumped by this one and don’t know what line of code to write next.

Thanks for taking the time to read this, I’m happy to add any further information you may need. Any assistance is both valued and appreciated.

Writing out this explanation has helped me understand a bit more about what is need from my app, I think. My confusion started with creating the ‘asset’ class object. I was assuming the object would be created using AppleScript somehow. Now, I think, it is intended to be created as a class in Xojo named ‘Asset’ which includes the six properties listed in the FCPX.sdef dictionary (is there any way to display the class details in this forum?). I’ve written the following code in my HandleAppleEvent event:

[code]dim s, t as String

/// this code is for debugging and will display the contents of the AE as a string
dim ae as AppleEvent = theEvent
s = ae.PrintDesc
t = ae.PrintDesc(True)
////

if StrComp (eventID, “crel”, 0) = 0 then 'thank you Thomas Templeton
dim theAsset as new asset 'create the new asset object
dim theObjSpecifier as new AppleEventObjectSpecifier 'create the new object specifier

/// the code needed here should associate theObjSpecifier with theAsset object

theEvent.ReplyObjectSpecifier = theObjSpecifier
end if[/code]

Am I on the right track here? FCPX requires my app to return an object specifier for the new asset object created. How do I associate theObjSpecifier with the theAsset? And am I returning it to FCPX the correct way?

Hello,
in an app of mine I use these applescripts. The target is QuickTimePlayer, but the hope is that they may contain something useful to unblock your situation. In fact they deal with AppleEventObjectSpecifier, which in this case is a property since it needs to be kept alive.

Public Property myDocument as AppleEventObjectSpecifier

[code]dim ae As AppleEvent

ae=new AppleEvent(“core”,“clos”,“com.apple.QuickTimePlayerX”)
ae.ObjectSpecifierParam("----")=MyDocument
ae.EnumeratedParam(“savo”)="no "
if ae.Send then
end if

dim ae As AppleEvent

ae=new AppleEvent(“MVWR”,“expo”,“com.apple.QuickTimePlayerX”)
ae.ObjectSpecifierParam("----")=MyDocument
ae.FolderItemParam(“kfil”)=toFile
ae.StringParam(“expp”)=“Audio Only”
if ae.Send then
end if

dim ae As AppleEvent
dim o As AppleEventObjectSpecifier

ae=new AppleEvent(“core”,“getd”,“com.apple.QuickTimePlayerX”)
o=GetIndexedObjectDescriptor(“docu”,nil,1)
ae.ObjectSpecifierParam("----")=o
if ae.Send then
MyDocument=ae.ReplyObjectSpecifier
end if

dim ae As AppleEvent

ae=new AppleEvent(“MVWR”,“nwar”,“com.apple.QuickTimePlayerX”)
if ae.Send then
MyDocument=ae.ReplyObjectSpecifier
end if

[/code]

Thank you, Carlo, for your post. It’s the first Xojo code I’ve seen that uses either objectDescriptor or objectSpecifier. In Xojo documentation there are only cursory descriptions and nearly zero examples for many of the AE methods and properties. In fact, the terms ‘descriptor’, ‘specifier’, and ‘identifier’ seem to be used loosely in documentation with little in the way of explanation. But your code is encouraging. At least it’s evidence that AE communication with Apple apps is possible with Xojo. I’ve been studying your code and have this question.

  • To properly create the asset class object FCPX wants my app to ‘make’, I need to include the asset’s unique identifier. I don’t see how this is possible yet. GetUniqueIDObjectDescriptor appears to let you get an object using its unique ID, but I’ve found no explanation of how to actually get a unique ID from an object. I can see how to do it in Swift with a simple call, but not with Xojo or MBS functions yet.

Thank you, again, for taking the time to reply.