On macOS, the osascript command line tool can be used to run AppleScript and JavaScript, both of which have access to the Apple Events API.
For most of the API, the translation is quite straightforward. E.g.
tell application "Terminal" to quit
translates to:
Application("Terminal").quit()
Moreover, in JS there is a commandsOfClass function that lists available actions:
osascript -l JavaScript -e 'Application("Terminal").commandsOfClass()'
# close, count, delete, doScript, duplicate, exists,
# getURL, make, move, open, print, quit, save
osascript -l JavaScript -e 'Application("System Events").commandsOfClass()'
# abortTransaction, attachActionTo, attachedScripts, beginTransaction, cancel, click,
# close, confirm, connect, count, decrement, delete, disconnect, doFolderAction,
# doScript, duplicate, editActionOf, enable, endTransaction, exists, increment,
# keyCode, keyDown, keyUp, keystroke, logOut, make, move, open, perform, pick,
# print, quit, removeActionFrom, restart, save, select, shutDown, sleep, start, stop
But AppleScript has some more obscure events, in particular the aevtrlgo ("really log out") one:
tell application "loginwindow" to «event aevtrlgo»
I can't even type the «» characters in the Terminal, so here's a copy-paste-able version:
printf 'tell application "loginwindow" to \xc2\xabevent aevtrlgo\xc2\xbb' | osascript
Now, how can I do this «event aevtrlgo» in JavaScript?
I've tried things like:
Application("loginwindow").rlgo();
Application("loginwindow").aevtrlgo();
Application("loginwindow").reallyLogOut();
Application("loginwindow").event("rlgo");
Application("loginwindow").event("aevtrlgo");
Application("loginwindow")["«event aevtrlgo»"]();
But I always get the exact same response:
execution error: Error on line 1: Error: Message not understood. (-1708)
Plus Application("loginwindow").commandsOfClass() yields an empty list.