Close the applescript application after running the shell script

I was wondering if it is possible for an applescript application to run a shell script and then exit before the shell script completes. This would be useful when starting the server for a certain amount of time. Instead of constantly running in the background, is there a way to run the 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 executed as an application, it will start the server properly. However, runScript.app will continue to work. The server will continue to work even if applescript is a forced shutdown. Is there a way for it to automatically stop as soon as the server starts up?

thanks

+4
source share
2 answers

Try it. 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 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 &" 
+4
source

You can add a condition to your Applescript so that it โ€œignores application responsesโ€ and then it goes on to what else is in your applescript, including its output.

The Apple website has details: https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html

+1
source

All Articles