applescript 或 shell 脚本方式到我。 e. grep 应用程序 "status" 在 i 之后。 e. killall - 停止它

applescript or shell script way to i. e. grep an applications "status" after i. e. killall -STOP it

如果我通过

暂停应用程序
killall -STOP

它,有没有办法读取这个"status"以备后用?我想写一个简短的脚本来检查应用程序是否已经停止,如果已经停止则通过

重新启动它
killall -CONT

如果没有,我希望能够暂停它。

它是这样工作的。使用此脚本,您可以暂停和取消暂停程序。

set shellOutput1 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '1'; else echo '2'; fi; exit 0"

if shellOutput1 contains "2" then

    tell application "Finder"
        set visible of process "<name of the process>" to false
    end tell

end if

set notificationName to "<program name>"

set shellOutput2 to do shell script "PROCESSNAME='<name of the process>'; GREPPID=$(pgrep $PROCESSNAME); if [ -z $GREPPID ]; then echo '3'; exit 0; else PSSTATUS=$(ps -o state= -p $GREPPID); if [ $PSSTATUS == 'T' ]; then killall -CONT $PROCESSNAME; echo '1'; else killall -STOP $PROCESSNAME; echo '2'; fi; fi; exit 0"

if shellOutput2 contains "1" then

    tell application "Finder"
        set visible of process "<name of the process>" to true
    end tell

    display notification notificationName & " wieder gestartet!" sound name "default"

else if shellOutput2 contains "2" then
    display notification notificationName & " angehalten!" sound name "default"
else if shellOutput2 contains "3" then
    display notification notificationName & " läuft nicht!" sound name "default"
end if

return shellOutput2