Terminal command script

Joined
Aug 13, 2012
Messages
3
Reaction score
0
Points
1
I have recently started running a minecraft server which requires me to type:

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui.

into terminal and execute to boot the sever. The command has to be run from the directory which contains the sever files, which seems to be my default terminal location when I open terminal.

My question, is there an easy way to write a script, so I can double click an icon on my desktop and the sever will start?
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Open a Terminal and type: nano mcserver.sh (or whatever you want to name it).
When the editor opens, type this:
#!/bin/sh

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

Now type: control-o (that's an O not a zero)
This saves the file. Now type control-x to quit.
Now you need to make it executable. Type chmod +x mcserver.sh
Now you should be able to run it by typing: ./mcserver.sh (notice the ./). Also it's not really necessary to put the .sh if you don't want it.
 
OP
W
Joined
Aug 13, 2012
Messages
3
Reaction score
0
Points
1
This is great, thanks. Is there any way to trigger this via an alias/desktop icon?
 
Joined
Apr 6, 2011
Messages
1,291
Reaction score
43
Points
48
Location
Louisville, KY - USA
Your Mac's Specs
MBP 17" 2011, 2.3GHz Intel Quad-Core i7, 8GB RAM, MacMini 2011, 2.7GHz Intel Dual-Core i7, 8GB RAM
Use Automator to do it. I dont have it in front of me, but you can set up a shell script as an app.
 
OP
W
Joined
Aug 13, 2012
Messages
3
Reaction score
0
Points
1
Assume I am a complete idiot (mostly true where scripting on mac is concerned). I like the automator approach, but it doesn't seem to like the 'boot' command.

I have opened automator with a 'do shell script' window. Shell is set to /bin/bash and pass input is set to 'to stdin'

In my command/script entry window I have:

cd /Users/James/Desktop/Server
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
say "server booted"

The command has to be run from the directory where the server files are contained, hence the cd command. When tested or run outside automator it seems to do nothing. When the test application is stopped inside automator the say command triggers.

**Edit**
After rebooting (which closed java) the automator script worked fantastically. Thanks for the help
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top