2012-07-01 2 views
4

셸 스크립트를 실행하는 데 applescript 응용 프로그램이 가능한지 궁금한가요? 그러고 나서 셸 스크립트 실행이 끝나기 전에 종료하십시오. 이는 주어진 시간 동안 서버를 실행할 때 유용합니다. 백그라운드에서 끊임없이 실행되도록하기 위해 애플 스크립트를 필요로하는 대신 독립적으로 기능을 실행할 수있는 방법이 있습니까?셸 스크립트 실행 후 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

시도해보십시오. 행운을 빕니다.

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

감사 :

애플 사이트 세부 사항이있다! – Phro

1

당신은 "응용 프로그램이 응답을 무시"가 당신의 AppleScript를에 조건을 추가 할 수 있으며, 다음을 종료 포함하여 AppleScript로에있는 어떤 다른로 이동합니다. 도움을 https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html

+2

'애플리케이션 응답 무시 '.'do shell script' 명령에는이 제어문이 작동하지 않습니다. – jackjr300

+0

고마워, 나는 그 사실을 몰랐다. 적절한 방법은 스크립트를 백그라운드에두고 응답을 파일 또는/dev/null로 리디렉션하는 것입니다. 다음 페이지에서 "기타 문제"섹션을 참조하십시오. https://developer.apple.com/library/mac/technotes/tn2065/_index.html – Dave

관련 문제