All the Apple Event commands, including Send core event and Send Finder event, are obsolete and have been removed from the Method Editor in Omnis Studio 10 and above. You can use the oFinderEvent object class to call Apple Finder events, as described below.
Note that in Omnis Studio 8.0.3; Apple Events do not work on macOS Sierra and are therefore no longer supported in that release of Omnis Studio. The commands have been moved from the Apple events… group and placed into the Obsolete commands group in the Method Editor and are no longer supported.
To replace the functionality of the old “Send Finder Event” commands, this release includes a new Object class called oFinderEvent which contains a number of methods which run AppleScript to execute the equivalent Apple Finder events, such as a Get File Info event or a Duplicate Files event. The AppleScript is run using the $runapplescript() Omnis method from inside each method in the object class.
To use the object class and these methods, click on the Class Wizard option in the Studio Browser, then click on Object, select the oFinderEvent option (available on macOS only), name the object class (or keep the name oFinderEvent) and press Return: a copy of the object class template is added to your library. Open the Method Editor for the class in which you want to use the Finder events (such as a window, menu or toolbar class), and then create an Object variable in the class, setting its subtype to the oFinderEvent object you created.
You can call the methods in your code, and run the AppleScript as required, using the Omnis command Do ObjVar.$methodname() using the appropriate method name, as below.
Some of the methods can take a file path as the first parameter, or if this is omitted or empty a file selection dialog will open. The title of the dialog can be customized by editing the cOpenFilesTitle class variable.
$getfileinfo([cFilePath])
Sends a Get File Info event: equivalent Send finder event {Get File Info} command
$duplicatefiles([cFilePath])
Sends a Duplicate Files event: equivalent Send finder event {Duplicate Files} command
$makealiasforfiles([cFilePath])
Sends a Make Alias For Files event: equivalent Send finder event {Make Alias For Files} command
$openfiles([cFilePath])
Sends a Open Files event: equivalent Send finder event {Open Files} command
$printfiles([cFilePath])
Sends a Print Files event: equivalent Send finder event {Print Files} command
$revealfiles([cFilePath])
Sends a Reveal Files event: equivalent Send finder event {Reveal Files} command
$emptytrash()
Sends a Empty Trash event: equivalent Send finder event {Empty Trash} command
$restart()
Sends a Restart Macintosh event: equivalent Send finder event {Restart Macintosh} command
$shutdown()
Sends a Shutdown Macintosh event: equivalent Send finder event {Shutdown Macintosh} command
$sleep()
Sends a Sleep Macintosh event: equivalent Send finder event {Sleep Macintosh} command
The object has three instance variables which you can use in your code to handle errors:
iErrCode
The error code generated by the last command. 0 for no error.
iErrText
The error text generated by the last command.
iScript
The AppleScript sent by the last command.
The following legacy commands are not supported in the latest version on macOS: Send finder event {Show About}, Send finder event {Share Files}, Send finder event {Show Clipboard}.
You can examine the Omnis code and AppleScript in each method inside the object class. For example, various simple operations are handled in a generic method $simpleop and the operation is passed in as a parameter:
# $simpleop method
# pOperation param receives 'Empty', 'Restart', 'Shut down', or 'Sleep' msg
Begin text block
Text: tell application "Finder" (Carriage return)
Text: [pOperation] (Carriage return)
Text: end tell (Carriage return)
End text block
Get text block iScript
Do $root.$runapplescript(iScript,iErrCode,iErrText)
Quit method iErrCode
Each of the new methods in the object class includes the equivalent old command as a comment to help you map your code to the new methods.
# Send finder event {Empty Trash} ## old command
Quit method $cinst.$simpleop("Empty") ## new method