I would like to parse an AppleEvent such as:
DispachNotification “the message to send” fromMac “TheMac2019” fromAppOrScript “theScriptSource.scpt”
The corresponding side description is:
<dictionary title="AETest Terminology">
<suite name="AETest Suite" code="AEts" description="AETest commands">
<command name="DispachNotification" code="AEtsNoVS" description="Sending text to Custom Notification System">
<direct-parameter type="text" description="Text to announce as notification"/>
<parameter name="fromMac" code="NoVs" description="Option to provide the Computer source." type="integer" optional="yes"/>
<parameter name="fromAppOrScript" code="NoVa" description="Option to provide the application or script source." type="text" optional="yes"/>
</command>
</suite>
</dictionary>
I can get the direct parameter (which correspond the the text message), using:
if StrComp (eventClass, "AEts", 0) = 0 then
// Here we handle various commands that are described in the sdef file:
if StrComp (eventID, "NoVS", 0) = 0 then ' DispachNotificationToVigilante
dim s as String = theEvent.StringParam("----")
MessageBox(s) // How do I get the other two parameters???
end
end if
but not the other two (which are the computer id number, and the script filename.
With using “----”, you ask for the default parameter (the one right after the command).
Now, we can see “fromMac”'s 4 characters code is “NoVs”, so replace the command with this code:
This is a follow-up of this thread.
My original question was how "to parse and appleEvent. Which it was solved.
Now I wonder how to build an AppleEvent from an Xojo application rather than using applescript
tell application "VigilanteProHelper"
DispachMessage "textMessage" fromMac "iMac"
end tell
When I send the above code from “Script Editor” application, the “VigilanteProHelper” responds correctly my showing a messageBox: with the textMessage being:
“textMessage” plus “iMac”.
So far perfect…
The raw appleEvent looks looks this:
‘AEts’‘NoVS’{ ‘NoVM’:‘utxt’(“iMac”), ‘----’:‘utxt’(“textMessage”), &‘subj’:null(), &‘csig’:65536 }
So I am now trying to achieve the same by sending and Applevent (without using applescript) using an other application build with Xojo.
Var ae As AppleEvent
Var list As AppleEventDescList
ae = New AppleEvent("AEts", "NoVS", "com.Luxware.VigilanteProHelper")
I am using the bundle identifier. Is this OK?
How should I continue ??
I tried with:
list.AppendString("----")= "Luciano"
list.AppendString("NoVM")= "theMac"
If Not ae.Send Then
MessageBox("The AppleEvent could not be sent.")
End If
(Forget about theList, that was taken from an example from the Xojo “Documentation”)
Following your help, I can now send the apple event, although it seems that it is not handled.
If I use AppleScript (as reported in my above message) it works fine. This means that the structure of the ‘sdef’ file is correct.
But the “pure” appleEvent is not processed.
I am sending the appleEvent using this code:
Var ae As AppleEvent
ae = New AppleEvent("AEts", "NPGs", "com.Luxware.VigilanteProHelper")
ae.StringParam("----")= "Luciano"
ae.StringParam("NoVM")= "theMac"
var s as string
If ae.Send Then // AE successfully sent
If ae.ReplyBoolean Then
s = "Yes (handled)"
Else
s = "Yes (unhandled)"
End If
MessageBox(s)
Else
s = "Not sent"
MessageBox(s)
End If
The results is: “Yes (unhandled)”
On the other hand, the code below trigger the application to quit.
Var ae As AppleEvent
ae = New AppleEvent("aevt", "quit", "com.Luxware.VigilanteProHelper")
var s as string
If ae.Send Then // AE successfully sent
If ae.ReplyBoolean Then
s = "Yes (handled)"
Else
s = "Yes (unhandled)"
End If
MessageBox(s)
Else
s = "Not sent"
MessageBox(s)
End If
I am sending below the link to the sdef file in case this could be the cause of the problem.
And in a separate message the code + resource files, in case you have time to look into the code. I am not sure you can successfully build the app, since it relays also on external AppleScript Libraries. But I guess the relevant part is in the sdef file and in the AppleEventReceived handler
Thanks a lot.
You’re using a different AppleEventID here (“NPGs” instead of “NoVS”). I’m not sure it’s intentional. If it’s not, the explanation could be that “NPGs” doesn’t return anything (“NPGs” is to copy a signature to the clipboard; have you checked to paste, e.g. in TextEdit, to see whether it works?).
Be aware that ReplyBoolean doesn’t necessarily mean the event was handled (the ae.Send’s result is for that).
Based on the Sdef file, it appears neither “NoVS” nor “NPGs” events should return a result. ae.ReplyBoolean is a return value from the app, as would be ae.ReplyInteger (if your command expects a result, like “count documents”). The app may very well not return anything, especially for a “copy signature to clipboard” command.
I made two small apps. The first one is scriptable (just accepting few commands as test via AppleScript) and also able to receive ‘raw’ appleEvents (such as generic ones as ‘aevt/quit’ or ‘aevt /odoc’, but also custom such as ‘Lucs/MkUp’), based on the info stored in ‘AppleScriptVocabulary.sdef’ file. It is called ‘LuxAEModule’.
The second one is the one that send AppleEvent, called ‘AESender’.
Initially the generic appleEvents (‘aevt /odoc’) worked all the time while the custom one not. I thought there was an error in the ‘AppleScriptVocabulary.sdef’. At this moment, since generic AE went through I excluded a problem of privacy/privilege from the System.
But the I tried using AppleScript and both generic and custom appleEvents worked perfectly. Thus, I thought the error was in the ‘AppleEventReceived’ Handler, but I could find one. Since appleScript was fine, I continued excluding a problem of privacy/privilege from the System.
Then I tried calling an Applescript not using ‘Script Editor’ but using shell/osascript within the ‘AESender’ App. When I did this, it ‘magically’ appeared the Privacy alert, which I allowed. After this everything worked, both standard and custom raw AppleEvents.
My understanding is that:
generic AppleEvents such as ‘aevt/quit’ or ‘aevt /odoc’ do not need any special privilege. They always work.
Custom raw AppleEvents do not trigger a Privacy alert message.
shell/’osascript -e’, does trigger a Privacy alert message, which opens the door for the raw AppleEvents.
I am sharing the link of the code and associated files of these two apps, in case might be of use for someone else.
That’s more complex than that. Here’s what I know on the subject:
1: The Script Editor can always (or may it be most of the time?) send AppleEvents. For some reasons, it seems to be “whitelisted” from the security system.
2: A standard application that sends AppleEvents can behave in several ways:
2.1: if you don’t notarise the app (and provide a NSAppleEventsUsageDescription key), the AppleEvent will just fail (no dialog asking for permission; you just get an error back in the AppleEvent (that you can see in Xojo using declares, like for others AppleEvent errors)).
2.2: with a not notarised app and using the shell, the dialog asking for permission appears. I guess it’s because the shell is notarised/trusted (not sure about this one).
2.3: if you notarise the app and provide the NSAppleEventsUsageDescription key, the dialog also appears. That’s the expected way to use.
2.4: if your app has already been permitted, it can continue sending AppleEvents freely (except when bugs reset the trust system, as it happens).
2.5: if the dialog appears and the user denies, one can go into System Preferences→Security&Privacy→Automation and allow there. IIRC, sending others AppleEvents while in denied state will again trigger the dialog.
I do have the ‘NSAppleEventsUsageDescription key = true’ (so this should be out of the equation).
I am always a bit confused by the notarisation step.
I thought that if you keep the compiled application in the User/Applications folder of your own computer, then you do not need “notarisation”. But maybe I am wrong.
Can someone please indicate where to find differences between ‘signing’ and ‘notarise’ an application in Xojo. (It seems to me that during the building of an app with Xojo, the signing step in included)
And how to notarise an app if you need only for you won use in your own computer.
This should be a string (which will be put in the dialog to the user, like “I need to control the Finder for the asked task”), not a boolean.
That was true at some point, but I’m not sure it’s still so. And I’m also unsure whether this was for code-signing only or also notarisation (which came after).
But I’m seeing Beatrix’s reply and she answered that
The Signing step uses your developer signing certificate (that you specify by clicking on the Sign step in the navigator to add a digital signature to your app.
Notarization is a separate manual step whereby you upload your packaged or zipped app to Apple and they do a quick check to make sure it is packaged correctly and send you back a code to mark it as Notarized. It is however a requirement to prevent additional security messages from appearing in recent versions of macOS.
Overall, things are a bit more clear now.
Yet, based on Greg feedback it seems that you need Notarization if you want to distribute your software. It might no be necessary for “personal” use.
Indeed after triggering the permission security messages with the shell/osascript (mentioned above) it seems that applications made with Xojo can communicate among them by both AppleScript (either .scpt files or via shell/osascript) and also by ‘raw’ appleEvents such as:
Var ae As AppleEvent
ae = New AppleEvent("aevt", "quit", "com.Luxware.VigilanteProHelper")