« OneDriveバージョンチェッカv3 | トップページ | twitter投稿用画像4分割 »

OneDrive関連プロセス一斉終了


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#メニューバーの● ■ ▶︎ の右三角をクリックして実行してください↑
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application


set listBundleID to {"com.microsoft.OneDrive", "com.microsoft.SharePoint-mac", "com.microsoft.OneDrive.OneDriveFileHandler", "com.microsoft.OneDrive.DownloadAndGo", "com.microsoft.OneDriveUpdater", "com.microsoft.SkyDriveLauncher", "com.microsoft.OneDriveLauncher", "com.microsoft.OneDriveStandaloneUpdater", "com.microsoft.SyncReporter"} as list
repeat with itemBundleID in listBundleID
  set strBundleID to itemBundleID as text
  try
    tell application id strBundleID to quit
  end try
end repeat


repeat with itemBundleID in listBundleID
  set strBundleID to itemBundleID as text
  try
    set ocidResultsArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
    set numCntArray to ocidResultsArray count
    set ocidRunApp to (ocidResultsArray's objectAtIndex:0)
    ###通常終了
    set boolDone to ocidRunApp's terminate()
    ####強制終了
    set boolDone to ocidRunApp's forceTerminate()
  end try
end repeat







set listAppName to {"OneDrive", "Microsoft SharePoint", "OneDrive File Handler", "OneDrive File Launcher", "OneDriveUpdater", "OneDriveStandaloneUpdater", "SyncReporter", "OneDriveLauncher", "LauncherDisabler"} as list


repeat with itemAppName in listAppName
  set strAppName to itemAppName as text
  set strCommandText to "/bin/ps -alxe | grep \"" & strAppName & "\" | grep -v \"grep\" | awk '{ print $2 }'" as text
  set strResponce to (do shell script strCommandText) as text
log strResponce
  set AppleScript's text item delimiters to "\r"
  set listPID to every text item of strResponce
  set AppleScript's text item delimiters to ""
  
  if (count of listPID) = 0 then
log "対象プロセス無し"
  else
    repeat with itemPID in listPID
      ###プロセスを終了させる
doQuitApp2PID(itemPID)
    end repeat
  end if
end repeat


repeat with itemAppName in listAppName
  ##念押し
  try
    set strCommandText to "/usr/bin/killall -QUIT '" & itemAppName & "'" as text
    set strResponce to (do shell script strCommandText) as text
  on error
    try
      set strCommandText to "/usr/bin/killall -KILL '" & itemAppName & "'" as text
      set strResponce to (do shell script strCommandText) as text
    end try
  end try
end repeat




###################################
########アプリケーションを終了させる
###################################
to doQuitApp2PID(argPID)
  set strPID to argPID as text
  #### killallを使う場合
  set strCommandText to ("/bin/kill -15 " & strPID & "") as text
  set ocidCommandText to refMe's NSString's stringWithString:strCommandText
  set ocidTermTask to refMe's NSTask's alloc()'s init()
ocidTermTask's setLaunchPath:"/bin/zsh"
ocidTermTask's setArguments:({"-c", ocidCommandText})
  set listResults to ocidTermTask's launchAndReturnError:(reference)
log listResults
  if item 1 of listResults is true then
log "正常終了"
  else
    try
      set strCommandText to ("/bin/kill -9 " & strPID & "") as text
      set strResponse to (do shell script strCommandText) as text
    end try
  end if
end doQuitApp2PID


|

« OneDriveバージョンチェッカv3 | トップページ | twitter投稿用画像4分割 »

AppleScript OneDrive」カテゴリの記事