Reputation: 374
I was wondering if it is possible for an applescript application to run a shell script, then quit before the execution of the shell script is completed. This would be useful when running a server for a given amount of time. Instead of needing the applescript to be constantly running in the background, is there any way to run a function independently?
set server_name to text returned of (display dialog "Choose server." default answer "")
set success to do shell script "if [ -f \"/Users/jessefrohlich/Documents/Minecraft/" & server_name & "/minecraft_server.jar\" ]; then
echo 1;
else
echo 0;
fi"
if success is equal to "1" then
do shell script "cd /Users/jessefrohlich/Documents/Minecraft/" & server_name & "
java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
else
display dialog "Sorry, the file you chose is invalid."
end if
When the above is run as an application, it will launch the server properly. However, the application runScript.app
will continue to run. The server will keep running even if the applescript is force quit. Is there any way to have it quit automatically, as soon as the server is launched?
Thanks
Upvotes: 4
Views: 3867
Reputation: 21
You can add a condition to your Applescript to have it "ignore application responses", and it will then go on to whatever else is in your applescript, including quitting it.
The Apple Site has details: https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html
Upvotes: 1
Reputation: 19032
Try this. Good luck.
-- "> /dev/null" redirects standout out to nowhere land
-- - you can use some other file path if you want to capture its output
-- "2>&1" redirects standard error to the same place as standard out
-- - 2 stands for standard error
-- - 1 stands for standard out
-- - > is the redirect symbol
-- - & changes redirect's output from a file to a file descriptor (in this case standard out)
-- & the trailing & sends the process to the background
do shell script "cd /Users/jessefrohlich/Documents/Minecraft/" & server_name & " java -Xmx1024M -Xms1024M -jar minecraft_server.jar > /dev/null 2>&1 &"
Upvotes: 4