AppleScript强制退出Java(JAR)程序? [英] AppleScript to force quit Java (JAR) programs?

查看:260
本文介绍了AppleScript强制退出Java(JAR)程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我在MAC OS上运行了Java(jar)应用程序.我正在使用AppleScript运行Java程序,并且运行良好.现在,我喜欢使用AppleScript关闭Java程序.我需要 强制退出 该Java程序.我使用了以下AppleScript,

I run a Java (jar) application on MAC OS. I am using an AppleScript to run the Java program and it works fine. Now, I like to use an AppleScript to close the Java program. I need to Force Quit the Java program. I used the following AppleScript,

set app_name to "NPC"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)

运行Java程序的AppleScript称为"NPC.app",当我运行"NPC.app"时,其在活动上显示为 NPC NPC.npc 监视应用程序.上面设置为删除NPC应用程序的代码不会删除 NPC (这是"NPC.app")或 NPC.npc (这是Java程序) ).我收到以下错误消息,

The AppleScript that runs the Java program is called "NPC.app" When I run "NPC.app" it shows as NPC and NPC.npc on the Activity Monitor application. The above code which is set to remove the NPC application does not remove either NPC (this is the "NPC.app") or NPC.npc (this is the Java program). I get the following error,

错误"sh:第0行:kill:1180 1182:参数必须是进程或作业 ID"数字1

error "sh: line 0: kill: 1180 1182: arguments must be process or job IDs" number 1

1180是 NPC 的PID,而1182是 NPC.npc 的PID.

1180 being the PID for NPC and 1182 being the PID for NPC.npc in the Activity Monitor.

什么是强制退出Java程序的正确AppleScript?

What is the correct AppleScript to force quit the Java program?

推荐答案

这是将关闭Java程序的AppleScript,

Here is the AppleScript that will close Java programs,

tell application "Terminal"
    do shell script "ps ax | grep \"java.*$1\" | grep -v grep | awk '{ print \"kill \" $1 }' | sh"
    quit
end tell

*参考: 感谢:wojciechka♦♦ *

这篇关于AppleScript强制退出Java(JAR)程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆