Using the Mac OS X Services Menu from a Java / Swing Application

I would like to make the Java / Swing application compatible with the Services menu available on Mac OS X. For example, so that a user can select text in JTextArea and convert it to speech using Services → Speech → Start text in text . Is there an easy way to achieve this? (The app should still run on platforms other than Mac OS X.)

+3
source share
4 answers

This is similar to working with Mac OS X Leopard, without changing the original application. So I lost interest in the answer (how to make it work for Tiger). Thanks for your input.

0
source

OSXAdapter ( Java Java-). , , , OS X , , OS X.

+3

I tend to say no. If I remember correctly, services are only available for Cocoa applications, and Java applications are not Cocoa applications.

+1
source

If all you need is the end result of converting text to speech, you can try calling the command say "using ProcessBuilder, something like this:

String stuffYouWantToSay = "StackOverflow Rocks!";
Process p = null;
try {
    ProcessBuilder pb = new ProcessBuilder("/usr/bin/say", stuffYouWantToSay);
    p = pb.start();
} catch (Exception e) {
    // handle the error
    return;
}

This will not add it to the services menu, but you will still get the same effect.

Be sure to check the man page for "say" as you can change the voice.

0
source

Source: https://habr.com/ru/post/1699180/


All Articles