update: 2015/06/14
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}
repeat
# query memory free (MB)
set vmStats to (text 12 thru -2 of (do shell script "vm_stat | grep 'Pages free'")) * 4096 / 1024 / 1024
# if vmStats <= 500 MB
if vmStats <= 500 then
# show dialog message (for debug used)
#display dialog vmStats with title "Memory Free (MB)" buttons {"OK"} default button 1
# kill your app
tell application "System Events"
set ProcessList to name of every process
# "my_app" is your app name
if "my_app" is in ProcessList then
set ThePID to unix id of process "my_app"
# kill "my_app" process
do shell script "kill -KILL " & ThePID
end if
end tell
# restart the OS
tell application "Finder"
restart
end tell
end if
# delay 30 second
delay 30
end repeat
return input
end run
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。