执行shell脚本后退出applescript应用程序

时间:2012-07-01 21:47:32

标签: shell applescript quit nonlinear-functions

我想知道AppleScript应用程序是否可以运行shell脚本,然后在shell脚本执行完成之前退出。在运行服务器一段时间时,这将非常有用。而不是需要Applecript在后台持续运行,有没有办法独立运行一个函数?

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

当上述内容作为应用程序运行时,它将正确启动服务器。但是,应用程序runScript.app将继续运行。即使强制退出AppleScript,服务器也会继续运行。一旦服务器启动,有没有办法让它自动退出?

由于

2 个答案:

答案 0 :(得分:4)

试试这个。祝你好运。

-- "> /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 &"

答案 1 :(得分:1)

您可以在Applescript中添加一个条件,让它“忽略应用程序响应”,然后它将继续执行您的AppleScript中的任何其他内容,包括退出它。

Apple网站有详细信息:https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html