2015年5月28日 星期四

Processing: Call AppleScript to Kill Process & Restart System

since: 2015/05/28
update: 2015/05/28


A. 撰寫 AppleScript:
    1. 開啟 Automator:

    2. Automator > 檔案 > 新增 > 應用程式 > 選擇:

    3. 工具程式 > 執行 AppleScript > 拖拉到右方

    4. 預設程式碼:
on run {input, parameters}
   
    (* Your script goes here *)
   
    return input
end run

    5. 修改如下:
on run {input, parameters}

    tell application "System Events"
        set ProcessList to name of every process
       
        if "APP_client" is in ProcessList then
            set ThePID to unix id of process "APP_client"
            do shell script "kill -KILL " & ThePID
        end if
       
        if "APP_server" is in ProcessList then
            set ThePID to unix id of process "
APP_server"
            do shell script "kill -KILL " & ThePID
        end if  
     
    end tell
   
    tell application "Finder"
        restart
    end tell   
   
    return input
end run


    6. 檔案 > 儲存: 
        /Lanli/RD/myScript.app

-----------------------------------------------------------------------------------------------

B. 開啟 Processing 撰寫程式如下:
void setup() {
  size(200, 200);
}

void draw() {
  // draw() must be present for mousePressed() to work
}

void mousePressed() {
  open("/Lanli/RD/myScript.app");
  exit();
}