문제

I want to execute a Applescript command that checks if some process is crashed and then restarts that app. I've already have the script but now i need to call it from my c++ code.

The script is:

tell application "Activity Monitor" to run  --We need to run Activity Monitor
tell application "System Events" to tell process "Activity Monitor"
    tell radio button 1 of radio group 1 of group 1 of toolbar 1 of window 1 to click --Using the CPU View 
    tell outline 1 of scroll area 1 of window 1 -- working with the list 
        set notResponding to rows whose value of first static text contains "Not Responding" -- Looking for Not responding process
        repeat with aProcess in notResponding
            set pid to value of text field 5 of aProcess  -- For each non responding process retrieve the PID 
            if pid is not "" then do shell script ("kill -9 " & pid) -- KILL the PID. 
        end repeat
    end tell
end tell
도움이 되었습니까?

해결책

You can call "osascript" which is a command line tool to execute apple script. Use the built-in C "system" command to execute it. This may sound like a platform dependant hack, well it is! Wrapping the code into a designated class should be the way.

By the way: Is listening for some process activity using AppleScript a good way? You probably might be able to read process information using built-in unix features. Think about it

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top