Marek Curda

Greenhorn
+ Follow
since Oct 29, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marek Curda

Campbell Ritchie wrote:They require the date in month‑day‑year format. That is the problem (I think). When it says "07/04/16...", it is ambiguous; is that 7th April or 4th July?


Well since it asks for  "MM/dd/yy HH:mm:ss" in man pmset one would think that it would work or maybe this code just doesnt return the proper date:


... I tried to split it up but still same error...


7 years ago
sorry I dont seem to see a button to edit my posts....  man pmset shows examples of using the command and one of them is "pmset schedule wake "07/04/16 20:00:00"" where I just use sleep instead of wake so it should be the same..
7 years ago

Campbell Ritchie wrote:

Marek Curda wrote:. . . When I use the exact same command in terminal it works... But I tried it just to be sure and it gives me same error...

Please copy'n'paste the exact command which works. You may be passing date and time as separate arguments. Also have a look at the man pages for pmset and see how many different arguments you can pass.



well the command that works is: pmset sleepnow


it also works when I make a String
7 years ago

Knute Snortum wrote:Could it be that the command wants a date in DD/MM/YY format?



When I use the exact same command in terminal it works... But I tried it just to be sure and it gives me same error...
7 years ago

Knute Snortum wrote:

Cannot run program "/usr/bin/sudo "


You have a space inside the quotes.  Remove it and it should run.  (And remove the other spaces at the end of commands too.)


I thought I had to have them to make spaces between the parameters... after removing the spaces the cannot run program is gone but I get this again:


and this is the array I am using :


Maybe it is impossible to do so I should probably make a timer that would run and after its done it would run this :

Thats the only way I can think of to get it working...
7 years ago

Campbell Ritchie wrote:Welcome to the Ranch

Question too hard for this forum: will be moved elsewhere.

If you need sudo at the terminal, you will doubtless need to include sudo in the commands array. I would suggest you pass that array to Arrays.toString(cmd) and print it out, which will allow you to see whether the format is the same as you are passing to the terminal.
Also, you didn't say whether you are using Runtime#exec to run your program, or something else.



Hi:) Sorry for posting in beginners, I didnt know where else to put it as I am still a beginner myself :)

yes I am using to run it, as I didnt find any other way to run macOS commands from java

this is what I get from the array :


Also I am confused as to why did this run without needing sudo but when I type the same thing in terminal it asks for sudo...
7 years ago
Hi guys I am new to JAVA and because I wanted to create something useful for myself I went on and tried to make an app that would put my computer to sleep after certain time.

Now I searched through internet how to run mac OS commands from java and got it partially working... I need to run this in order to put my computer to sleep:



and this is what I got:



where "time" gets me current date in the proper format and "tajm" gets me desired time. And when I run it I get this:


But if I run the code in terminal it works just fine even with the date... also I tried this(just to test if sudo is needed):


but that gives me


I also edited sudoers so pmset doesn't require a password.. so I can run this without a problem


but whenever I try to run the first code it just doesn't go through...
I would appreciate any help. Thank you in advance
7 years ago