| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | プロセスクリーニング |
| 006 |
|
| 007 |
|
| 008 | PlugInLibraryService(999999) を終了させます |
| 009 | バンドルIDは共通で |
| 010 | com.apple.filesystems.netfs.PlugInLibraryService |
| 011 | ユーザー権限で動作します |
| 012 |
|
| 013 | SafariでローカルMacOS上のHTMLファイル開いたりすると増えます |
| 014 | 特に異常にCPUを使用したりすることは今のところないですが |
| 015 | 気持ち悪いので、定期的に落とすようにする場合に使用 |
| 016 |
|
| 017 |
|
| 018 | com.cocolog-nifty.quicktimer.icefloe *) |
| 019 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 020 | use AppleScript version "2.8" |
| 021 | use framework "Foundation" |
| 022 | use framework "AppKit" |
| 023 | use scripting additions |
| 024 |
|
| 025 | property refMe : a reference to current application |
| 026 |
|
| 027 | ################################ |
| 028 | #OBJCで終了 ほとんど出来ないが数個はこれで終了する |
| 029 | set boolDone to doQuitAutomatorRunner("com.apple.filesystems.netfs.PlugInLibraryService") |
| 030 |
|
| 031 |
|
| 032 | ################################ |
| 033 | #SIGTERM(ソフトな終了) |
| 034 | set listProcessID to doGetProcessID("PlugInLibraryService") |
| 035 | repeat with itemProcessID in listProcessID |
| 036 | set strCmd to ("/bin/kill -SIGTERM " & itemProcessID & "") as text |
| 037 | do shell script strCmd |
| 038 | end repeat |
| 039 |
|
| 040 | ################################ |
| 041 | #SIGHUP(ハードな終了=ハングアップ回避) |
| 042 | set listProcessID to doGetProcessID("PlugInLibraryService") |
| 043 | repeat with itemProcessID in listProcessID |
| 044 | set strCmd to ("/bin/kill -SIGHUP " & itemProcessID & "") as text |
| 045 | do shell script strCmd |
| 046 | end repeat |
| 047 |
|
| 048 | ################################ |
| 049 | #SIGKILL(強制終了) |
| 050 | set listProcessID to doGetProcessID("PlugInLibraryService") |
| 051 | repeat with itemProcessID in listProcessID |
| 052 | set strCmd to ("/bin/kill -SIGKILL " & itemProcessID & "") as text |
| 053 | #実行するか?=強制終了は別途考慮が必要 |
| 054 | # do shell script strCmd |
| 055 | end repeat |
| 056 |
|
| 057 | ################################ |
| 058 | #QUIT(コア付き終了) |
| 059 | set listProcessID to doGetProcessID("PlugInLibraryService") |
| 060 | repeat with itemProcessID in listProcessID |
| 061 | set strCmd to ("/bin/kill -QUIT " & itemProcessID & "") as text |
| 062 | #実行するか?=コアダンプは別途考慮が必要 |
| 063 | # do shell script strCmd |
| 064 | end repeat |
| 065 |
|
| 066 | return |
| 067 |
|
| 068 |
|
| 069 | ################################ |
| 070 | #doGetProcessID |
| 071 | to doGetProcessID(argProcessName) |
| 072 | set strProcessName to argProcessName as text |
| 073 | #システムインフォを取得して |
| 074 | set recordSystemInfo to (system info) as record |
| 075 | #ユーザーIDを取得 |
| 076 | set strUID to (short user name of recordSystemInfo) as text |
| 077 | #ユーザーIDでコマンドを整形して |
| 078 | set strCmd to ("/usr/bin/pgrep -u " & strUID & " " & strProcessName & " || true") as text |
| 079 | #実行 |
| 080 | set strStdOut to (do shell script strCmd) as text |
| 081 | if strStdOut is "" then |
| 082 | set listProcessID to {} as list |
| 083 | return listProcessID |
| 084 | end if |
| 085 | #リストにする |
| 086 | set strDelim to AppleScript's text item delimiters |
| 087 | set AppleScript's text item delimiters to return |
| 088 | set listProcessID to every text item of strStdOut |
| 089 | set AppleScript's text item delimiters to strDelim |
| 090 | return listProcessID |
| 091 | end doGetProcessID |
| 092 |
|
| 093 | ################################## |
| 094 | #NSRunningApplication |
| 095 | to doQuitAutomatorRunner(argBundleID) |
| 096 | set strBundleID to argBundleID as text |
| 097 | set ocidAppArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)) |
| 098 | repeat with itemApp in ocidAppArray |
| 099 | set boolDone to itemApp's terminate() |
| 100 | if boolDone is false then |
| 101 | set boolDone to itemApp's forceTerminate() |
| 102 | end if |
| 103 | end repeat |
| 104 | #terminateAutomaticallyTerminableApplications 自動終了 |
| 105 | refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications() |
| 106 | return true |
| 107 | end doQuitAutomatorRunner |