Java Opening and operating programs in java on a mac

AI Thread Summary
A user in a Java course on Mac seeks guidance on launching external programs like TextEdit or Terminal from Java code. The discussion highlights that the Java Runtime class can execute external applications using the exec functions. A specific code example using ProcessBuilder to open Skype is provided, but the user encounters a "permission denied" error when attempting to run it. Clarification is given that "myArg" is a placeholder for an argument, which can be removed if not needed. The cause of the permission issue is uncertain, with suggestions that it may relate to macOS settings rather than Java itself, prompting the need for further assistance from someone knowledgeable about Mac permissions.
Yoyo_Guru
Messages
32
Reaction score
0
I started taking a java course at my school and we are required to use macs. I looked for how to open other programs like text edit or the terminal but the code segments I found only worked for java. Is it possible to have a java program open other programs like text edit or the terminal on a mac? And if so how?
 
Technology news on Phys.org
Yoyo_Guru said:
I started taking a java course at my school and we are required to use macs. I looked for how to open other programs like text edit or the terminal but the code segments I found only worked for java. Is it possible to have a java program open other programs like text edit or the terminal on a mac? And if so how?

I'm not entirely sure what you're asking here. You mean you want to launch some external program from Java code?

If so, the Runtime class has exec functions that can do that:

http://download.oracle.com/javase/6/docs/api/index.html

There's so many ways of doing it. And exec isn't always the best way, but it might be what you're looking for.

I found a page with a rather large number of different ways to run external programs from Java:

http://www.rgagnon.com/javadetails/java-0014.html

Not sure why you want to do that in this case, but that's up to you. :smile:
 
ok, thanks. I got a little farther but everytime I run it I get an error saying permission denied. Do you know how to get around this? Also some of the terms used on the site confused me so I kinda had to guess. Here is what I wrote, maybe I just wrote something wrong.

Process p = new ProcessBuilder("/Applications/Skype.app", "myArg").start();
 
Yoyo_Guru said:
ok, thanks. I got a little farther but everytime I run it I get an error saying permission denied. Do you know how to get around this? Also some of the terms used on the site confused me so I kinda had to guess. Here is what I wrote, maybe I just wrote something wrong.

Process p = new ProcessBuilder("/Applications/Skype.app", "myArg").start();
Keep in mind that the "myArg" means you're passing the application an argument of "myArg". That was just a placeholder in the example in the docs. Unless you're trying to pass that as a parameter (don't see why), you can just remove it.

As for the permission problem, I'm not entirely sure. I assume you caught an IOException? I would guess that it's your operating system and not the Java Virtual Machine (but I could be wrong). As for how to fix it, I'm not totally sure. Someone who knows Macs will have to chime in here. There's probably some way of giving the application permission to launch Skype, but I personally have no clue how to do it on a Mac and would be reaching.
 
Alright, thanks a lot.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top