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

查看:37
本文介绍了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"时,它在活动中显示为 NPCNPC.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,

error "sh: line 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

*参考:MAC OS - 有没有办法关闭 Java 程序?

感谢:wojciechka ♦ ♦*

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

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