Macとかの雑記帳

メモリ解放と、Finder、Dock、メニューバーの再起動をするアプリです。Mac用のメモリ解放アプリはいくつかありますが、メニューバーの再起動までしてくれるものが見つからなかったので自作した物です。

メモリ解放アプリ

以前、メニューバー関係で酷い目に合ったのと、毎回ウィンドウが表示され、そこから実行するのが面倒だったので、クリックすれば勝手に処理して勝手に終わってくれるものが欲しくて作りました。

  • Growl以外ウィンドウ等は何も表示されません。
  • クリックすれば数十秒程で処理が完了します。
  • Finderを再起動するので、ファイル等をコピー、移動中には実行しないでください。

※メモリ解放部分は、Libera Memoryの作者であるものかのさんのブログで以前公開されていた下のコマンドを。

$ du -sx / &> /dev/null & sleep 5 && kill $!

※Growlのメモリ情報の部分はわかばマークのMacの備忘録さんのこちらの記事を引用させていただきました。

--disk usage
do shell script "du -sx / &> /dev/null & sleep 25 && kill $!"
delay 2

--Finderを再起動
do shell script "killall Finder"

--Menubarを再起動
do shell script "killall SystemUIServer"

delay 5

--Dockを再起動
do shell script "killall Dock"

delay 6

property rt : return as text

tell application "Growl"
set the allNotificationsList to ¬
{"Release mem"}

set the enabledNotificationsList to ¬
{"Release mem"}

register as application ¬
"Release mem" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Release mem"

notify with name ¬
¬
"Release mem" title ¬
"Memory notification" description ¬
(my Status() as Unicode text) application name ¬
"Release mem" icon of application "Release mem"
end tell
on Status()
set memoryStatus to do shell script "top -l 1 | head -10 | grep PhysMem"

set wiredMem to word 2 of memoryStatus
set activeMem to word 4 of memoryStatus
set inactiveMem to word 6 of memoryStatus
set usedMem to word 8 of memoryStatus
set freeMem to word 10 of memoryStatus

set swapusage to do shell script "sysctl vm.swapusage"
set theSwap to "Swap : " & word 7 of swapusage & " (" & word 4 of swapusage & ")"

set grepLine to do shell script "top -l 1 | head -10 | grep VM"
set pageins to (((round (word 7 of grepLine as number) / 4096 * 100) / 100 * 16) as text) & "M"
set pageouts to (((round (word 10 of grepLine as number) / 4096 * 100) / 100 * 16) as text) & "M"

return "空き  : " & freeMem & rt & "固定  : " & wiredMem & rt & "使用  : " & activeMem & rt & "非使用 : " & inactiveMem & rt & "確保中 : " & usedMem & rt & rt & theSwap & rt & "Page Ins : " & pageins & rt & "Page Outs : " & pageouts & rt
end Status

https://gist.github.com/3899495#file_gistfile1.applescript

補足

10.6以前で使う場合

下の赤字の部分を変更します。

du -sx / &> /dev/null & sleep 10 && kill $!

10.5等で使う場合は、以下のように変更すればたぶん使えます。

du -s / &> /dev/null & sleep 10 && kill $!

起動時間を短くする場合

下の10を5とかに変更して、duコマンドの実行時間を変更します。

sleep 10

スポンサード リンク