Calling MEL from AppleScript and vice-versa


You can pass MEL commands to Maya in an Open Scripting Architecture language (usually AppleScript) by telling Maya to execute a string. For example:

// This is AppleScript code
tell application "Maya" 	execute "sphere;" end tell

The execute verb returns the MEL result.

You can call AppleScript from MEL indirectly using the Mac OS osascript command.

// This is MEL code
system("osascript \"tell application finder to activate\"");

This method of calling AppleScript through the command line through MEL’s system command can be tricky, because each level has its own special characters and quoting rules. Use the osascript command’s -i (include) flag to get the script from a file instead of the command line.

Read the osascript manual page (man osascript) or search Apple’s Knowledge Base for more information on using the osascript command.

Also, search Apple’s Knowledge Base for the latest information regarding AppleScripts support of HFS (:) and POSIX (/) path separators.