4

我想知道 applescript 应用程序是否可以运行 shell 脚本,然后在 shell 脚本执行完成之前退出。在给定时间运行服务器时,这将很有用。不需要applescript在后台不断运行,有没有办法独立运行一个函数?

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 被强制退出,服务器也会继续运行。有没有办法让它在服务器启动后自动退出?

谢谢

4

2 回答 2

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 &"
于 2012-07-01T22:19:49.897 回答
1

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

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

于 2012-07-02T17:02:56.640 回答