AppleScript Microsoft Edge

[edgemac]キャッシュをゴミ箱に入れる(更新 GraphiteDawnCache追加)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 各種キャッシュファイルをゴミ箱に移動します
# 削除はご自分で判断してください
# 
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

set strBundleID to "com.microsoft.edgemac"

###################################
########まずは処理するアプリケーションを終了させる
###################################
doQuitApp2UTI(strBundleID)


###################################
########ヘルパーの終了を確認する
###################################
set listHelperBundleID to {"com.microsoft.edgemac", "com.microsoft.edgespotlight", "com.microsoft.EdgeUpdater", "com.microsoft.edgemac.framework.AlertNotificationService", "com.microsoft.edgemac.helper", "com.microsoft.edgemac.helper.plugin", "com.microsoft.edgemac.helper.renderer"} as list

repeat with itemID in listHelperBundleID
doQuitApp2UTI(itemID)
end repeat

###################################
######## ローカルドメインエラーになるけど
###################################
log doMoveToTrash("/Library/Application Support/Microsoft/EdgeUpdater")
log doMoveToTrash("/Library/Microsoft/EdgeUpdater")


###################################
######## Application Supportフォルダー
###################################

log doMoveToTrash("~/Library/Application Support/Microsoft/EdgeUpdater")


log doMoveToTrash("~/Library/Application Support/Microsoft Edge/component_crx_cache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Crashpad")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/CrashpadMetrics-active.pma")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Diagnostic Data")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Diagnostic Data-wal")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/extensions_crx_cache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/GrShaderCache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/GraphiteDawnCache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/SafetyTips")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/ShaderCache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/SmartScreen")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/extensions_crx_cache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/extensions_crx_cache")
###ゲストは丸ごと削除
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Guest Profile")

###プロファイル内のキャッシュ
repeat with itemIntNo from 1 to 10 by 1
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Asset Store/assets.db")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/blob_storage")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/BudgetDatabase")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/commerce_subscription_db")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/coupon_db")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/data_reduction_proxy_leveldb")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/DawnCache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Download Service")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/GPUCache")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/IndexedDB")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/optimization_guide_hint_cache_store")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Platform Notifications")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Service Worker")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Storage")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/VideoDecodeStats")
log doMoveToTrash("~/Library/Application Support/Microsoft Edge/Profile " & itemIntNo & "/Web Applications")
  
end repeat
###################################
########Containers
###################################
log doMoveToTrash("~/Library/Containers/com.microsoft.edgemac.wdgExtension/Data/Library/Caches")

###################################
########HTTPStorages
###################################
log doMoveToTrash("~/Library/HTTPStorages/com.microsoft.EdgeUpdater")
log doMoveToTrash("~/Library/HTTPStorages/com.microsoft.edgemac")


###################################
########LOGS
###################################
log doMoveToTrash("~/Library/Logs/Microsoft Edge")
log doMoveToTrash("~/Library/Logs/Microsoft Edge (GPU)")
log doMoveToTrash("~/Library/Logs/Microsoft Edge (Renderer)")

###################################
########EdgeUpdater
###################################
log doMoveToTrash("~/Library/Microsoft/EdgeUpdater")

###################################
########EdgeUpdater
###################################
log doMoveToTrash("~/Library/Microsoft/MicrosoftSoftwareUpdate/Actives/com.microsoft.edgemac")

###################################
########キャッシュ
###################################

log doMoveToTrash("~/Library/Caches/com.microsoft.edgemac")
log doMoveToTrash("~/Library/Caches/Microsoft Edge")


###################################
########Saved Application State
###################################
log doMoveToTrash("~/Library/Saved Application State/com.microsoft.edgemac")
log doMoveToTrash("~/Library/Saved Application State/com.microsoft.edgemac.savedState")

###################################
########WebKit
###################################

log doMoveToTrash("~/Library/WebKit/com.microsoft.edgemac")

###################################
########キャッシュNSTemporaryDirectory
###################################
### T
set ocidTempDir to (refMe's NSTemporaryDirectory())
set ocidTemporaryTPathURL to refMe's NSURL's fileURLWithPath:(ocidTempDir)
log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac")
log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper")
log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper-(GPU)")
log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper-(Renderer)")

###
set ocidTempURL to ocidTemporaryTPathURL's URLByDeletingLastPathComponent()
### C
set ocidTemporaryCPathURL to ocidTempURL's URLByAppendingPathComponent:"C"

log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac")
log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper")
log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper-(GPU)")
log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.microsoft.edgemac.helper-(Renderer)")



###################################
########処理 ゴミ箱に入れる
###################################

to doMoveToTrash(argFilePath)
  ###ファイルマネジャー初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  #########################################
  ###渡された値のClassを調べてとりあえずNSURLにする
  set refClass to class of argFilePath
  if refClass is list then
return "エラー:リストは処理しません"
  else if refClass is text then
log "テキストパスです"
    set ocidArgFilePathStr to (refMe's NSString's stringWithString:argFilePath)
    set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
    set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
  else if refClass is alias then
log "エイリアスパスです"
    set strArgFilePath to (POSIX path of argFilePath) as text
    set ocidArgFilePathStr to (refMe's NSString's stringWithString:strArgFilePath)
    set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
    set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
  else
    set refClass to (className() of argFilePath) as text
    if refClass contains "NSPathStore2" then
log "NSPathStore2です"
      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:argFilePath)
    else if refClass contains "NSCFString" then
log "NSCFStringです"
      set ocidArgFilePath to argFilePath's stringByStandardizingPath
      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
    else if refClass contains "NSURL" then
      set ocidArgFilePathURL to argFilePath
log "NSURLです"
    end if
  end if
  #########################################
  ###
  -->false
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
  -->true
  set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
  #########################################
  ###NSURLがエイリアス実在するか?
  set ocidArgFilePath to ocidArgFilePathURL's |path|()
  set boolFileAlias to appFileManager's fileExistsAtPath:(ocidArgFilePath)
  ###パス先が実在しないなら処理はここまで
  if boolFileAlias = false then
log ocidArgFilePath as text
log "処理中止 パス先が実在しない"
return false
  end if
  #########################################
  ###NSURLがディレクトリなのか?ファイルなのか?
  set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)
  # log (item 1 of listBoolDir)
  # log (item 2 of listBoolDir)
  # log (item 3 of listBoolDir)
  if (item 2 of listBoolDir) = ocidTrue then
    #########################################
log "ディレクトリです"
log ocidArgFilePathURL's |path| as text
    ##内包リスト
    set listResult to appFileManager's contentsOfDirectoryAtURL:(ocidArgFilePathURL) includingPropertiesForKeys:{refMe's NSURLPathKey} options:0 |error|:(reference)
    ###結果
    set ocidContentsPathURLArray to (item 1 of listResult)
    if ocidContentsPathURLArray ≠ (missing value) then
      ###リストの数だけ繰り返し
      repeat with itemContentsPathURL in ocidContentsPathURLArray
        ###ゴミ箱に入れる
        set listResult to (appFileManager's trashItemAtURL:itemContentsPathURL resultingItemURL:(missing value) |error|:(reference))
      end repeat
    end if
  else
    #########################################
log "ファイルです"
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsAliasFileKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "エイリアスは処理しません"
return false
    end if
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSymbolicLinkKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "シンボリックリンクは処理しません"
return false
    end if
    set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSystemImmutableKey) |error|:(reference)
    if (item 2 of listBoolDir) = ocidTrue then
log "システムファイルは処理しません"
return false
    end if
    ###ファイルをゴミ箱に入れる
    set listResult to (appFileManager's trashItemAtURL:ocidArgFilePathURL resultingItemURL:(missing value) |error|:(reference))
  end if
return true
end doMoveToTrash

###################################
########アプリケーションを終了させる
###################################
to doQuitApp2UTI(argUTI)
  set strUTI to argUTI as text
  ### まずは普通に終了を試みる
  try
    tell application id strUTI to quit
  end try
delay 1
  set ocidResultsArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:strUTI
  set numCntArray to ocidResultsArray count
  if numCntArray ≠ 0 then
    set ocidRunApp to ocidResultsArray's objectAtIndex:0
    
    ###通常終了
    set boolDone to ocidRunApp's terminate()
    ####強制終了
    set boolDone to ocidRunApp's forceTerminate()
    
    #### killallを使う場合
    set ocidExecAppURL to ocidRunApp's executableURL()
    set ocidFileName to ocidExecAppURL's lastPathComponent()
    set strFileName to ocidFileName as text
    
    set strCommandText to ("/usr/bin/killall -z " & strFileName & "") 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 listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
    
    
    ####killを使う場合
    set ocidPID to ocidRunApp's processIdentifier()
    set strPID to ocidPID as text
log strPID
    set strCommandText to ("/bin/kill -9 " & 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 listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
    
    
  end if
end doQuitApp2UTI



|

[Edge]URLを開く


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

#!/usr/bin/env osascript


set strURL to ("https://news.yahoo.co.jp") as text

tell application "Microsoft Edge"
  set numCntWindow to (count of every window) as integer
  if numCntWindow = 0 then
    ##ブランクのタブを開いて
    set objWindowID to make new window with properties {title:"edge://newtab"}
    tell objWindowID
      set numCnttab to (count of every tab) as integer
      if numCnttab = 0 then
        #新しいタブを生成(まぁこれは無いけど)
make new tab with properties {URL:strURL}
      else
        #ブランクのタブをにURLをセットする
        tell front tab
          set URL to strURL
        end tell
      end if
    end tell
  else
    tell front window
      set strWindowName to title as text
      tell front tab
        set strTabURL to URL as text
      end tell
      ##ブランクならそURLを表示
      if strWindowName is "edge://newtab" then
        tell front tab
          set URL to strURL
        end tell
        ##URLが同じサイトならURLを表示
      else if strTabURL contains strURL then
        tell front tab
          set URL to strURL
        end tell
      else
        ##違うサイトなら新しいタブを開く
make new tab with properties {URL:strURL}
      end if
    end tell
  end if
end tell


|

バージョンチェッカーv3 MacAdminのRSSを使用しない方法


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

#!/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

###アプリケーションのバンドルID
set strBundleID to "com.microsoft.edgemac"
#
set strURL to ("https://go.microsoft.com/fwlink/?linkid=2093504") as text
#リダレイト先を取得
set strCommandText to ("/usr/bin/curl -s -L -I -w '%{url_effective}' \"" & strURL & "\" -o /dev/null")
set strResponse to (do shell script strCommandText) as text
#
set ocidURLString to refMe's NSString's stringWithString:(strResponse)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set ocidBaseURL to ocidURL's URLByDeletingPathExtension()
set ocidFileName to ocidBaseURL's lastPathComponent()
#
set ocidFileNameArray to ocidFileName's componentsSeparatedByString:("-")
set strVersion to ocidFileNameArray's lastObject() as text
log strVersion

################################################
###### インストール済みのパージョン
################################################
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
##バンドルからアプリケーションのURLを取得
set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
end if
##予備(アプリケーションのURL)
if ocidAppPathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
      set strAppPath to POSIX path of aliasAppApth as text
      set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
      set strAppPath to strAppPathStr's stringByStandardizingPath()
      set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
end if
set ocidFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist")
#####PLISTの内容を読み込んで
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
set ocidCfbundleversionPlist to ocidPlistDict's valueForKey:"CFBundleShortVersionString"
log ocidCfbundleversionPlist as text

################################################
###### チェック
################################################
set strCfbundleversionXML to strVersion as text
set strCfbundleversionPlist to ocidCfbundleversionPlist as text

if strCfbundleversionXML is strCfbundleversionPlist then
  set strTitle to ("最新版を利用中です") as text
  set strCom to ("最新版を利用中です\r" & strCfbundleversionXML) as text
  set strMes to (strTitle & "\rRSS:" & strCfbundleversionXML & "\rPLIST:" & strCfbundleversionPlist & "\rLink:" & strURL & "\rLocation:" & strResponse) as text
else
  set strTitle to ("アップデートがあります:" & strCfbundleversionXML) as text
  set strCom to ("アップデートがあります\r最新:" & strCfbundleversionXML & "\r使用中:" & strCfbundleversionPlist) as text
  set strMes to ("最新版ダウンロード:" & strURL & "\r" & strResponse) as text
end if

################################################
###### ダイアログ
################################################
set appFileManager to refMe's NSFileManager's defaultManager()

####ダイアログに指定アプリのアイコンを表示する
###アイコン名をPLISTから取得
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  set strIconPath to ocidIconFilePathURL's |path|() as text
end if

set recordResult to (display dialog strCom with title strTitle default answer strMes buttons {"クリップボードにコピー", "終了", "ダウンロード"} default button "ダウンロード" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "ダウンロード" then
  tell application "Finder"
open location strResponse
  end tell
end if
if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
end if


|

[com.microsoft.edgemac]全てのウィンドウの全てのタプのURLを取得する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application


###アプリケーションのバンドルID
set strBundleID to "com.microsoft.edgemac"
###エラー処理
tell application id strBundleID
  set numWindow to (count of every window) as integer
end tell
if numWindow = 0 then
return "Windowが無いので処理できません"
end if
##戻り値用
set listGetUrl to {} as list

###ダイアログの用意
set ocidAppPathURL to doGetAppPathURL(strBundleID)
set ocidIconFilePathURL to doGetIconPathURL(ocidAppPathURL)
set aliasIconFilePath to (ocidIconFilePathURL's absoluteURL()) as alias
###URLとタイトルを取得
tell application "Microsoft Edge"
  set listWindowID to id of every window
  repeat with itemWindowID in listWindowID
    tell window id itemWindowID
      set listTabID to (id of every tab)
      repeat with itemTabID in listTabID
        tell tab id itemTabID
          set strURL to URL as text
          set end of listGetUrl to strURL
        end tell
      end repeat
    end tell
  end repeat
end tell

log listGetUrl
##リストを改行区切りテキストに変換
set ocidURLArray to refMe's NSArray's alloc()'s initWithArray:(listGetUrl)
set ocidURLstr to ocidURLArray's componentsJoinedByString:("\n")
set strUrlText to ocidURLstr as text

########################
## ダイアログ
########################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strTITLE to ("URLリストです") as text
set strMessage to ("URLリストです") as text
try
  set recordResponse to (display dialog strMessage with title strTITLE default answer strUrlText buttons {"OK", "キャンセル", "クリップボードにコピー"} default button "クリップボードにコピー" cancel button "キャンセル" with icon aliasIconFilePath giving up after 20 without hidden answer) as record
on error strErrorMes number numErrorNO
log strErrorMes
log numErrorNO
return (missing value)
end try
if true is equal to (gave up of recordResponse) then
return "時間切れですやりなおしてください"
else if false is equal to (recordResponse) then
log "キャンセルしました"
return "キャンセルしました"
else if "クリップボードにコピー" is equal to (button returned of recordResponse) then
  try
    set strResponse to (text returned of recordResponse) as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strResponse))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strResponse as text
    end tell
  end try
else
log "キャンセルしました"
return (missing value)
end if

################################
## %エンコードをデコード
################################
on doUrlDecode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##デコード
  set ocidArgTextEncoded to ocidArgText's stringByRemovingPercentEncoding
  set strArgTextEncoded to ocidArgTextEncoded as text
return strArgTextEncoded
end doUrlDecode


########################
## bundle to AppPathURL
########################
to doGetAppPathURL(argBundleiD)
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleiD))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(argBundleiD))
  end if
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
        set aliasAppApth to (application file id strBundleID) as alias
      on error
log "アプリケーションが見つかりませんでした"
return (missing value)
      end try
    end tell
    set strAppPath to POSIX path of aliasAppApth as text
    set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
    set strAppPath to strAppPathStr's stringByStandardizingPath()
    set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
  end if
return ocidAppPathURL
end doGetAppPathURL


########################
## AppPathURL to AppIcon
########################
to doGetIconPathURL(argAppPathURL)
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to argAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to argAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ###ICONファイルが実際にあるか?チェック
  set appFileManager to refMe's NSFileManager's defaultManager()
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時用にデフォルトを用意する
  if boolExists is false then
    set strIconPath to "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    set ocidIconPathStr to refMe's NSString's stringWithString:(strIconPath)
    set ocidIconPath to ocidIconPathStr's stringByStandardizingPath()
    set ocidIconFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
  else
return ocidIconFilePathURL
  end if
end doGetIconPathURL

|

【日英判定】Edge2mirai_translate(みらい翻訳)


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

#!/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.6"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set appFileManager to refMe's NSFileManager's defaultManager()

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  else
log "テキストなし"
    set strReadString to "入力してください" as text
  end if
end if

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to (POSIX file "/System/Library/CoreServices/Tips.app/Contents/Resources/AppIcon.icns") as alias
set strTitle to ("入力してください") as text
set strMes to ("【日英判定】翻訳します\rSafariで開きます\r") as text
set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)

if (gave up of recordResult) is true then
return "時間切れです"
else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
else
  set strReturnedText to (text returned of recordResult) as text
end if
set ocidText to refMe's NSString's stringWithString:(strReturnedText)
###NSURLを使わないのでクエリー用に%エンコードしておく
set strEncText to doUrlEncode(strReturnedText)
set ocidEncText to refMe's NSString's stringWithString:(strEncText)
###########################
###URL整形
set strURL to ("https://miraitranslate.com/trial/") as text
set ocidBaseURL to refMe's NSString's stringWithString:(strURL)
##
(*
auto 自動
ja 日本
en 英語
ko 韓国
zh 北京語
zt 台湾語
it イタリア
id インドネシア
uk ウクライナ
es スペイン
th タイ
de ドイツ
fr フランス
vi ベトナム
pt ポルトガル
ru ロシア
*)


###########################
###【日本語判定】大まかな日本語陵域
set ocidPattern to refMe's NSString's stringWithString:("[ぁ-んァ-ン一-鿿]+")
###正規表現を定義↑のパターンでセット
set listRegex to refMe's NSRegularExpression's regularExpressionWithPattern:(ocidPattern) options:(0) |error|:(reference)
##error referenceしているので戻り値はリストだから
set ocidRegex to (item 1 of listRegex)
###入力文字列のレンジ
set ocidImputRange to refMe's NSMakeRange(0, ocidText's |length|())
###文字列の中に正規表現が最初に当てはまるレンジは?
set ocidRange to ocidRegex's rangeOfFirstMatchInString:(ocidText) options:0 range:(ocidImputRange)
###レンジのロケーションを取り出して
set ocidLocation to ocidRange's location()
##NSNotFoundなら
if ocidLocation = refNSNotFound then
log "日本語を含みません 日本語に翻訳します"
  ##
  set ocidEncBaseURL to ocidBaseURL's stringByAppendingPathComponent:("#en/ja/")
else
  ###あるなら
  set ocidEncBaseURL to ocidBaseURL's stringByAppendingPathComponent:("#ja/en/")
  
end if
###########################
###
set ocidGetURL to ocidEncBaseURL's stringByAppendingPathComponent:(ocidEncText)
set strGetURL to ocidGetURL as text

#############
tell application "Microsoft Edge"
activate
  tell front window
    set objNewTab to make new tab
    tell objNewTab to set URL to strGetURL
  end tell
end tell

#################################
##クオテーションの置換用
to doReplace(argOrignalText, argSearchText, argReplaceText)
  set strDelim to AppleScript's text item delimiters
  set AppleScript's text item delimiters to argSearchText
  set listDelim to every text item of argOrignalText
  set AppleScript's text item delimiters to argReplaceText
  set strReturn to listDelim as text
  set AppleScript's text item delimiters to strDelim
return strReturn
end doReplace
####################################
###### %エンコード
####################################
on doUrlEncode(argText)
  ##テキスト
  set ocidArgText to refMe's NSString's stringWithString:(argText)
  ##キャラクタセットを指定
  set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet
  ##キャラクタセットで変換
  set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet)
  ##テキスト形式に確定
  set strTextToEncode to ocidArgTextEncoded as text
  ###値を戻す
return strTextToEncode
end doUrlEncode




|

[zsh]Microsoft Edge アップデートスクリプト


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

#!/bin/zsh
## !/usr/bin/env zsh
#com.cocolog-nifty.quicktimer.icefloe
########################################
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export LANG=en_US.UTF-8
/bin/echo $LANG

###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。" 1>&2
  /bin/echo "sudo で実行してください" 1>&2
  ### path to me (VS CODEコンソールだとマルチバイト文字は文字化けする)
  SCRIPT_PATH="$0"
  STR_FILENAME=$(/usr/bin/basename "$SCRIPT_PATH")
  STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
  /bin/echo "/usr/bin/sudo \"$STR_CONTAINER_DIR_PATH/$STR_FILENAME\"" 1>&2
  /bin/echo "↑を実行してください" 1>&2
  exit 1
fi
###コンソールユーザー CONSOLE_USERはFinderでログインしていないと出ない
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
###実行しているユーザー名
CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー:" "$CURRENT_USER"

if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  /bin/echo "コンソールユーザー:" "$CONSOLE_USER"
fi
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"
########################################
STR_DEVICE_UUID=$(/usr/sbin/ioreg -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F'"' '{print $4}')
/bin/echo "デバイスUUID: " "$STR_DEVICE_UUID"

########################################
###ローカルのユーザーアカウントを取得
TEXT_RESULT=$(/usr/bin/dscl localhost -list /Local/Default/Users PrimaryGroupID | /usr/bin/awk '$2 == 20 { print $1 }')
###リストにする
TFS="\n"
read -d '\\n' -r -A LIST_USER <<<"$TEXT_RESULT"
LIST_USER=("${LIST_USER[@]:0:${#LIST_USER[@]}-1}")
/bin/echo "ユーザーリスト:" "$LIST_USER"
###リスト内の項目数
NUM_CNT=${#LIST_USER[@]}
/bin/echo "ユーザー数:" "$NUM_CNT"

###各ユーザーの最終ログアウト日
for ITEM_LIST in "${LIST_USER[@]}"; do
  if [[ -n $ITEM_LIST ]]; then
    /bin/echo "ユーザー${ITEM_LIST}"
    STR_CHECK_File_PATH="/Users/${ITEM_LIST}/Library/Preferences/ByHost/com.apple.loginwindow.$STR_DEVICE_UUID.plist"
    STR_LAST_LOGOUT=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" "$STR_CHECK_File_PATH")
    /bin/echo "ユーザー$ITEM_LIST の最終ログアウト日: " "$STR_LAST_LOGOUT"
  fi
done

########################################
##デバイス
#起動ディスクの名前を取得する
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/diskutil info -plist / >"/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  STARTUPDISK_NAME=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/defaults read "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist" VolumeName)
done
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"
########################################
###ダウンロード起動時に削除する項目
for ITEM_LIST in "${LIST_USER[@]}"; do
  USER_TEMP_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d)
  /bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
done
########################################
##基本メンテナンス
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Library"
  ##ライブラリの不可視属性を解除
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/chflags nohidden "/Users/${ITEM_LIST}/Library"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/SetFile -a v "/Users/${ITEM_LIST}/Library"
  ## Managed Itemsフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Library/Managed Items/.localized"
  ##
  /bin/chmod 777 "/Users/${ITEM_LIST}/Library/Caches"
  /bin/chmod 777 /Users/"${ITEM_LIST}"/Library/Caches/*
  ##
  /bin/chmod -Rf 755 "/Users/${ITEM_LIST}/Library/Fonts"
  /usr/sbin/chown -Rf "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Fonts"
  ##
  /bin/echo "ライブラリチェックDONE:" "${ITEM_LIST}"
done
########################################
## HOME
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  ## Developer
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Developer"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ## bin
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/bin"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  ##アクセス権チェック
  /bin/chmod 700 "/Users/${ITEM_LIST}/Movies"
  /bin/chmod 700 /"Users/${ITEM_LIST}/Music"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Pictures"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Downloads"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Documents"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Desktop"
  ##全ローカルユーザーに対して実施したい処理があれば追加する
  /bin/echo "ユーザーディレクトリチェックDONE" "${ITEM_LIST}"
done
########################################
## Public
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/chmod 755 "/Users/${ITEM_LIST}/Public"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Drop Box"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 733 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Documents"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Downloads"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Favorites"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Groups"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 770 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 750 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Guest"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 777 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 775 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  /bin/echo "パブリックチェックDONE" "${ITEM_LIST}"
done
########################################
## Applications
########################################
## Applications
for ITEM_LIST in "${LIST_USER[@]}"; do
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ##サブフォルダを作る
  LIST_SUB_DIR_NAME=("Demos" "Desktop" "Developer" "Documents" "Downloads" "Favorites" "Groups" "Library" "Movies" "Music" "Pictures" "Public" "Shared" "Sites" "System" "Users" "Utilities")
  ##リストの数だけ処理
  for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
    /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME"
    /bin/chmod 700 "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}"
    /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME/.localized"
  done
done
########################################
##シンボリックリンクを作る
if [[ ! -e "/Users/$CURRENT_USER/Applications/Applications" ]]; then
  /bin/ln -s "/Applications" "/Users/$CURRENT_USER/Applications/Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Applications" "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries" "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Applications" "/Users/$CURRENT_USER/Applications/Utilities/System Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Utilities" ]]; then
  /bin/ln -s "/Applications/Utilities" "/Users/$CURRENT_USER/Applications/Utilities/System Utilities"
fi

#################################
#インストール基本
#################################
###ここだけ変えればなんでいけるか?
STR_URL="https://go.microsoft.com/fwlink/?linkid=2093504"
###
STR_APP_NAME="Microsoft Edge"

LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/mktemp -d)
/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"

###ファイル名を取得
PKG_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
/bin/echo "PKG_FILE_NAME" "$PKG_FILE_NAME"

###ファイル名指定してダウンロード
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$PKG_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20

###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/osascript -e "tell application id \"com.microsoft.edgemac\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "$STR_APP_NAME" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (GPU)" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2

### インストール(上書き)を実行する
/usr/sbin/installer -pkg "$LOCAL_TMP_DIR/$PKG_FILE_NAME" -target / -dumplog -allowUntrusted -lang ja

################################################
###設定項目
STR_BUNDLEID="com.microsoft.edgemac"
STR_APP_PATH="/Applications/Microsoft Edge.app"
###アプリケーション名を取得
STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleDisplayName)
if [ -z "$STR_APP_NAME" ]; then
  STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleName)
fi
/bin/echo "アプリケーション名:$STR_APP_NAME"
################################################
### DOCKに登録済みかゴミ箱に入れる前に調べておく
##Dockの登録数を調べる
JSON_PERSISENT_APPS=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults read com.apple.dock persistent-apps)
NUN_CNT_ITEM=$(/bin/echo "$JSON_PERSISENT_APPS" | grep -o "tile-data" | wc -l)
/bin/echo "Dock登録数:$NUN_CNT_ITEM"

##Dockの登録数だけ繰り返し
NUM_CNT=0 #カウンタ初期化
NUM_POSITION="NULL" #ポジション番号にNULL文字を入れる
###対象のバンドルIDがDockに登録されているか順番に調べる
while [ $NUM_CNT -lt "$NUN_CNT_ITEM" ]; do
  ##順番にバンドルIDを取得して
  STR_CHK_BUNDLEID=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Print:persistent-apps:"$NUM_CNT":tile-data:bundle-identifier" "$HOME/Library/Preferences/com.apple.dock.plist")
  ##対象のバンドルIDだったら
  if [ "$STR_CHK_BUNDLEID" = "$STR_BUNDLEID" ]; then
    /bin/echo "DockのポジションNO: $NUM_CNT バンドルID:$STR_CHK_BUNDLEID"
    ##位置情報ポジションを記憶しておく
    NUM_POSITION=$NUM_CNT
  fi
  NUM_CNT=$((NUM_CNT + 1))
done

##結果 対象のバンドルIDが無ければ
if [ "$NUM_POSITION" = "NULL" ]; then
  /bin/echo "Dockに未登録です"
  PLIST_DICT="<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>"$STR_APP_PATH"</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults write com.apple.dock persistent-apps -array-add "$PLIST_DICT"
else
  ##すでに登録済みの場合は一旦削除
  /bin/echo "Dockの$NUM_POSITION に登録済み 削除してから同じ場所に登録しなおします"
  ##削除して
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Delete:persistent-apps:"$NUM_POSITION"" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###同じ内容を作成する
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION" dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":GUID integer "$RANDOM$RANDOM"" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 file-tile directory-tile
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-type string file-tile" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この親Dictに子要素としてtile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑子要素のtile-dataにキーと値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:showas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 2:フォルダ 41:アプリケーション 169 Launchpad とMission Control
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-type integer 41" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:displayas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:parent-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-label string $STR_APP_NAME" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:is-beta bool false" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この子要素のtile-dataに孫要素でfile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-data:_CFURLStringType integer 15" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:"$NUM_POSITION":tile-data:file-data:_CFURLString string file://"$STR_APP_PATH"" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
fi
###
/bin/echo "処理終了 DOCKを再起動します"
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/killall "Dock"

################################################
###
for ITEM_LIST in "com.microsoft.EdgeUpdater.update-internal" "com.microsoft.EdgeUpdater.update.system" "com.microsoft.EdgeUpdater.wake" "com.microsoft.EdgeUpdater"
do
/bin/launchctl stop -wF "$ITEM_LIST"
done
function STOP_LAUNCH_CTL() {
  if [ -e "$1" ]; then
  /bin/launchctll unload -wF $1
  fi
}
STOP_LAUNCH_CTL /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update-internal*
STOP_LAUNCH_CTL /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update.system*
STOP_LAUNCH_CTL /Library/LaunchDaemons/com.microsoft.EdgeUpdater.wake*
STOP_LAUNCH_CTL /Library/LaunchDaemons/com.microsoft.EdgeUpdater*

STOP_LAUNCH_CTL /Library/LaunchAgents/com.microsoft.EdgeUpdater.update-internal*
STOP_LAUNCH_CTL /Library/LaunchAgents/com.microsoft.EdgeUpdater.update.system*
STOP_LAUNCH_CTL /Library/LaunchAgents/com.microsoft.EdgeUpdater.wake*
STOP_LAUNCH_CTL /Library/LaunchAgents/com.microsoft.EdgeUpdater*

################################################
### クリーニング ローカルドメイン
#####不要なファイルをゴミ箱に
function DO_MOVE_TO_TRASH_SUDO() {
  if [ -e "$1" ]; then
    /bin/mkdir -p "/private/tmp/Cleanup At Startup/Trash"
    TRASH_DIR=$(/usr/bin/mktemp -d "/private/tmp/Cleanup At Startup/Trash/Edge.XXXXXXXX")

    /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
    /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
  fi
}
DO_MOVE_TO_TRASH_SUDO "/Library/Application Support/Microsoft/EdgeUpdater"
DO_MOVE_TO_TRASH_SUDO "/Library/Microsoft/EdgeUpdater"

DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update-internal*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update.system*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.wake*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater*

DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.update-internal*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.update.system*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.wake*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater*

################################################
### クリーニング ユーザードメイン
### 対象ファイルを起動時に削除する項目へ入れる
function DO_MOVE_TO_TRASH_USER() {
  local STR_DO_FILE_PATH="$1"
  local STR_DO_USERID="$2"

  if [ -e "$STR_DO_FILE_PATH" ]; then
    USER_TRASH_DIR=$(/usr/bin/sudo -u "$STR_DO_USERID" /usr/bin/mktemp -d "/private/tmp/Cleanup At Startup/.Trash/$STR_DO_USERID/Edge.XXXXXXXX")
    /bin/chmod 777 "$USER_TRASH_DIR"
    /bin/mv "$STR_DO_FILE_PATH" "$USER_TRASH_DIR"
  fi
}

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/mkdir -p "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  /bin/chmod 777 "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/Microsoft Edge" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.edgemac" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/ShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft Edge/Guest Profile" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GrShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GraphiteDawnCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/extensions_crx_cache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/Crashpad" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/component_crx_cache" "${ITEM_LIST}"

done



/bin/launchctl stop -wF com.microsoft.update.agent
/bin/launchctll unload -wF "/Library/LaunchAgents/com.microsoft.update.agent.plist"

exit 0


|

Microsoft Edge Update 少し修正

ダウンロード - microsoft20edge20update.zip


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

#!/bin/zsh
## !/usr/bin/env zsh
#com.cocolog-nifty.quicktimer.icefloe
########################################
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export LANG=en_US.UTF-8
/bin/echo $LANG

###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。" 1>&2
  /bin/echo "sudo で実行してください" 1>&2
  ### path to me (VS CODEコンソールだとマルチバイト文字は文字化けする)
  SCRIPT_PATH="$0"
  STR_FILENAME=$(/usr/bin/basename "$SCRIPT_PATH")
  STR_CONTAINER_DIR_PATH=$(/usr/bin/dirname "$SCRIPT_PATH")
  /bin/echo "/usr/bin/sudo \"$STR_CONTAINER_DIR_PATH/$STR_FILENAME\"" 1>&2
  /bin/echo "↑を実行してください" 1>&2
  exit 1
fi
###コンソールユーザー CONSOLE_USERはFinderでログインしていないと出ない
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
###実行しているユーザー名
CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー:" "$CURRENT_USER"

if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  /bin/echo "コンソールユーザー:" "$CONSOLE_USER"
fi
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"
########################################
STR_DEVICE_UUID=$(/usr/sbin/ioreg -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F'"' '{print $4}')
/bin/echo "デバイスUUID: " "$STR_DEVICE_UUID"

########################################
###ローカルのユーザーアカウントを取得
TEXT_RESULT=$(/usr/bin/dscl localhost -list /Local/Default/Users PrimaryGroupID | /usr/bin/awk '$2 == 20 { print $1 }')
###リストにする
TFS="\n"
read -d '\\n' -r -A LIST_USER <<<"$TEXT_RESULT"
LIST_USER=("${LIST_USER[@]:0:${#LIST_USER[@]}-1}")
/bin/echo "ユーザーリスト:" "$LIST_USER"
###リスト内の項目数
NUM_CNT=${#LIST_USER[@]}
/bin/echo "ユーザー数:" "$NUM_CNT"

###各ユーザーの最終ログアウト日
for ITEM_LIST in "${LIST_USER[@]}"; do
  if [[ -n $ITEM_LIST ]]; then
    /bin/echo "ユーザー${ITEM_LIST}"
    STR_CHECK_File_PATH="/Users/${ITEM_LIST}/Library/Preferences/ByHost/com.apple.loginwindow.$STR_DEVICE_UUID.plist"
    STR_LAST_LOGOUT=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" "$STR_CHECK_File_PATH")
    /bin/echo "ユーザー$ITEM_LIST の最終ログアウト日: " "$STR_LAST_LOGOUT"
  fi
done

########################################
##デバイス
#起動ディスクの名前を取得する
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/diskutil info -plist / >"/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  STARTUPDISK_NAME=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/defaults read "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist" VolumeName)
done
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"
########################################
###ダウンロード起動時に削除する項目
for ITEM_LIST in "${LIST_USER[@]}"; do
  USER_TEMP_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d)
  /bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
done
########################################
##基本メンテナンス
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Library"
  ##ライブラリの不可視属性を解除
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/chflags nohidden "/Users/${ITEM_LIST}/Library"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/SetFile -a v "/Users/${ITEM_LIST}/Library"
  ## Managed Itemsフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Library/Managed Items/.localized"
  ##
  /bin/chmod 777 "/Users/${ITEM_LIST}/Library/Caches"
  /bin/chmod 777 /Users/"${ITEM_LIST}"/Library/Caches/*
  ##
  /bin/chmod -Rf 755 "/Users/${ITEM_LIST}/Library/Fonts"
  /usr/sbin/chown -Rf "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Fonts"
  ##
  /bin/echo "ライブラリチェックDONE:" "${ITEM_LIST}"
done
########################################
## HOME
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  ## Developer
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Developer"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ## bin
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/bin"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  ##アクセス権チェック
  /bin/chmod 700 "/Users/${ITEM_LIST}/Movies"
  /bin/chmod 700 /"Users/${ITEM_LIST}/Music"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Pictures"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Downloads"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Documents"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Desktop"
  ##全ローカルユーザーに対して実施したい処理があれば追加する
  /bin/echo "ユーザーディレクトリチェックDONE" "${ITEM_LIST}"
done
########################################
## Public
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/chmod 755 "/Users/${ITEM_LIST}/Public"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Drop Box"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 733 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Documents"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Downloads"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Favorites"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Groups"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 770 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 750 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Guest"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 777 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 775 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  /bin/echo "パブリックチェックDONE" "${ITEM_LIST}"
done
########################################
## Applications
########################################
## Applications
for ITEM_LIST in "${LIST_USER[@]}"; do
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ##サブフォルダを作る
  LIST_SUB_DIR_NAME=("Demos" "Desktop" "Developer" "Documents" "Downloads" "Favorites" "Groups" "Library" "Movies" "Music" "Pictures" "Public" "Shared" "Sites" "System" "Users" "Utilities")
  ##リストの数だけ処理
  for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
    /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME"
    /bin/chmod 700 "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}"
    /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME/.localized"
  done
done
########################################
##シンボリックリンクを作る
if [[ ! -e "/Users/$CURRENT_USER/Applications/Applications" ]]; then
  /bin/ln -s "/Applications" "/Users/$CURRENT_USER/Applications/Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Applications" "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries" "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Applications" "/Users/$CURRENT_USER/Applications/Utilities/System Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Utilities" ]]; then
  /bin/ln -s "/Applications/Utilities" "/Users/$CURRENT_USER/Applications/Utilities/System Utilities"
fi

#################################
#インストール基本
#################################
###ここだけ変えればなんでいけるか?
STR_URL="https://go.microsoft.com/fwlink/?linkid=2093504"
###
STR_APP_NAME="Microsoft Edge"

LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/mktemp -d)
/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"

###ファイル名を取得
PKG_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
/bin/echo "PKG_FILE_NAME" "$PKG_FILE_NAME"

###ファイル名指定してダウンロード
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$PKG_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20

###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/osascript -e "tell application id \"com.microsoft.edgemac\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "$STR_APP_NAME" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (GPU)" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2

### インストール(上書き)を実行する
/usr/sbin/installer -pkg "$LOCAL_TMP_DIR/$PKG_FILE_NAME" -target / -dumplog -allowUntrusted -lang ja

################################################
###設定項目
STR_BUNDLEID="com.microsoft.edgemac"
STR_APP_PATH="/Applications/Microsoft Edge.app"
###アプリケーション名を取得
STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleDisplayName)
if [ -z "$STR_APP_NAME" ]; then
  STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleName)
fi
/bin/echo "アプリケーション名:$STR_APP_NAME"
################################################
### DOCKに登録済みかゴミ箱に入れる前に調べておく
##Dockの登録数を調べる
JSON_PERSISENT_APPS=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults read com.apple.dock persistent-apps)
NUN_CNT_ITEM=$(/bin/echo "$JSON_PERSISENT_APPS" | grep -o "tile-data" | wc -l)
/bin/echo "Dock登録数:$NUN_CNT_ITEM"

##Dockの登録数だけ繰り返し
NUM_CNT=0 #カウンタ初期化
NUM_POSITION="NULL" #ポジション番号にNULL文字を入れる
###対象のバンドルIDがDockに登録されているか順番に調べる
while [ $NUM_CNT -lt "$NUN_CNT_ITEM" ]; do
  ##順番にバンドルIDを取得して
  STR_CHK_BUNDLEID=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Print:persistent-apps:$NUM_CNT:tile-data:bundle-identifier" "$HOME/Library/Preferences/com.apple.dock.plist")
  ##対象のバンドルIDだったら
  if [ "$STR_CHK_BUNDLEID" = "$STR_BUNDLEID" ]; then
    /bin/echo "DockのポジションNO: $NUM_CNT バンドルID:$STR_CHK_BUNDLEID"
    ##位置情報ポジションを記憶しておく
    NUM_POSITION=$NUM_CNT
  fi
  NUM_CNT=$((NUM_CNT + 1))
done

##結果 対象のバンドルIDが無ければ
if [ "$NUM_POSITION" = "NULL" ]; then
  /bin/echo "Dockに未登録です"
  PLIST_DICT="<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$STR_APP_PATH</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults write com.apple.dock persistent-apps -array-add "$PLIST_DICT"
else
  ##すでに登録済みの場合は一旦削除
  /bin/echo "Dockの$NUM_POSITION に登録済み 削除してから同じ場所に登録しなおします"
  ##削除して
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Delete:persistent-apps:$NUM_POSITION" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###同じ内容を作成する
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:GUID integer $RANDOM$RANDOM" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 file-tile directory-tile
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-type string file-tile" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この親Dictに子要素としてtile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑子要素のtile-dataにキーと値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:showas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 2:フォルダ 41:アプリケーション 169 Launchpad とMission Control
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-type integer 41" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:displayas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:parent-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-label string $STR_APP_NAME" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:is-beta bool false" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この子要素のtile-dataに孫要素でfile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLStringType integer 15" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLString string file://$STR_APP_PATH" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
fi
###
/bin/echo "処理終了 DOCKを再起動します"
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/killall "Dock"

################################################
### クリーニング ローカルドメイン
#####不要なファイルをゴミ箱に
function DO_MOVE_TO_TRASH_SUDO() {
  if [ -e "$1" ]; then
    /bin/mkdir -p "/private/tmp/Cleanup At Startup/Trash"
    TRASH_DIR=$(/usr/bin/mktemp -d "/private/tmp/Cleanup At Startup/Trash/Edge.XXXXXXXX")
    /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
    /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
  fi
}
DO_MOVE_TO_TRASH_SUDO "/Library/Application Support/Microsoft/EdgeUpdater"
DO_MOVE_TO_TRASH_SUDO "/Library/Microsoft/EdgeUpdater"

DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update-internal*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.update.system*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater.wake*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchDaemons/com.microsoft.EdgeUpdater*

DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.update-internal*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.update.system*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater.wake*
DO_MOVE_TO_TRASH_SUDO /Library/LaunchAgents/com.microsoft.EdgeUpdater*

################################################
### クリーニング ユーザードメイン
### 対象ファイルを起動時に削除する項目へ入れる
function DO_MOVE_TO_TRASH_USER() {
  local STR_DO_FILE_PATH="$1"
  local STR_DO_USERID="$2"

  if [ -e "$STR_DO_FILE_PATH" ]; then
    USER_TRASH_DIR=$(/usr/bin/sudo -u "$STR_DO_USERID" /usr/bin/mktemp -d "/private/tmp/Cleanup At Startup/.Trash/$STR_DO_USERID/Edge.XXXXXXXX")
    /bin/chmod 777 "$USER_TRASH_DIR"
    /bin/mv "$STR_DO_FILE_PATH" "$USER_TRASH_DIR"
  fi
}

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/mkdir -p "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  /bin/chmod 777 "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/Microsoft Edge" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.edgemac" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/ShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft Edge/Guest Profile" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GrShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GraphiteDawnCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/extensions_crx_cache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/Crashpad" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/component_crx_cache" "${ITEM_LIST}"

done

exit 0


|

[bash]Microsoft Edgeのアップデート用

キャッシュの削除を少し追加

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# Microsoft Edgeのアップデート用
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
  /bin/echo "sudo で実行してください"
  ### path to me
  SCRIPT_PATH="${BASH_SOURCE[0]}"
  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\""
  /bin/echo "↑を実行してください"
  exit 1
else
  ###実行しているユーザー名
  CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行ユーザー:" "$CURRENT_USER"
fi
###コンソールユーザー CONSOLE_USERはFinderでログインしていないと出ない
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  /bin/echo "コンソールユーザー:" "$CONSOLE_USER"
fi
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"

########################################
###ローカルのユーザーアカウントを取得
TEXT_RESULT=$(/usr/bin/dscl localhost -list /Local/Default/Users PrimaryGroupID | /usr/bin/awk '$2 == 20 { print $1 }')
###リストにする
read -d '\\n' -r -a LIST_USER <<<"$TEXT_RESULT"
###リスト内の項目数
NUM_CNT=${#LIST_USER[@]}
/bin/echo "ユーザー数:" "$NUM_CNT"
########################################
STR_DEVICE_UUID=$(/usr/sbin/ioreg -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F'"' '{print $4}')
/bin/echo "デバイスUUID: " "$STR_DEVICE_UUID"
###各ユーザーの最終ログアウト日
for ITEM_LIST in "${LIST_USER[@]}"; do
  STR_CHECK_File_PATH="/Users/${ITEM_LIST}/Library/Preferences/ByHost/com.apple.loginwindow.$STR_DEVICE_UUID.plist"
  STR_LAST_LOGOUT=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" "$STR_CHECK_File_PATH")
  /bin/echo "ユーザー$ITEM_LIST の最終ログアウト日: " "$STR_LAST_LOGOUT"
done
########################################
##デバイス
#起動ディスクの名前を取得する
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/diskutil info -plist / >"/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist"
  STARTUPDISK_NAME=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/defaults read "/Users/${ITEM_LIST}/Documents/Apple/IOPlatformUUID/com.apple.diskutil.plist" VolumeName)
done
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"
########################################
###ダウンロード起動時に削除する項目
for ITEM_LIST in "${LIST_USER[@]}"; do
  USER_TEMP_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d)
  /bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
done
########################################
##基本メンテナンス
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Library"
  ##ライブラリの不可視属性を解除
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/chflags nohidden "/Users/${ITEM_LIST}/Library"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/SetFile -a v "/Users/${ITEM_LIST}/Library"
  ## Managed Itemsフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Library/Managed Items/.localized"
  ##
  /bin/chmod 777 "/Users/${ITEM_LIST}/Library/Caches"
  /bin/chmod 777 /Users/"${ITEM_LIST}"/Library/Caches/*
  ##
  /bin/chmod -Rf 755 "/Users/${ITEM_LIST}/Library/Fonts"
  /usr/sbin/chown -Rf "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Fonts"
  ##
  /bin/echo "ライブラリチェックDONE:" "${ITEM_LIST}"
done
########################################
## HOME
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  ## Developer
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Developer"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ## bin
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/bin"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo /usr/sbin/chown "${ITEM_LIST}" "$STR_CHECK_DIR_PATH"
  ##アクセス権チェック
  /bin/chmod 700 "/Users/${ITEM_LIST}/Movies"
  /bin/chmod 700 /"Users/${ITEM_LIST}/Music"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Pictures"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Downloads"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Documents"
  /bin/chmod 700 "/Users/${ITEM_LIST}/Desktop"
  ##全ローカルユーザーに対して実施したい処理があれば追加する
  /bin/echo "ユーザーディレクトリチェックDONE" "${ITEM_LIST}"
done
########################################
## Public
########################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/chmod 755 "/Users/${ITEM_LIST}/Public"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Drop Box"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 733 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Documents"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Downloads"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Favorites"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Groups"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 770 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 750 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
  ##########
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Guest"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 777 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  ##
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Public/Shared Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 775 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  /usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
  /bin/echo "パブリックチェックDONE" "${ITEM_LIST}"
done
########################################
## Applications
########################################
## Applications
for ITEM_LIST in "${LIST_USER[@]}"; do
  STR_CHECK_DIR_PATH="/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
  ##サブフォルダを作る
  LIST_SUB_DIR_NAME=("Demos" "Desktop" "Developer" "Documents" "Downloads" "Favorites" "Groups" "Library" "Movies" "Music" "Pictures" "Public" "Shared" "Sites" "System" "Users" "Utilities")
  ##リストの数だけ処理
  for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
    /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME"
    /bin/chmod 700 "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}"
    /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "$STR_CHECK_DIR_PATH/$ITEM_DIR_NAME/.localized"
  done
done
########################################
##シンボリックリンクを作る
if [[ ! -e "/Users/$CURRENT_USER/Applications/Applications" ]]; then
  /bin/ln -s "/Applications" "/Users/$CURRENT_USER/Applications/Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Applications" "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries" "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Applications" "/Users/$CURRENT_USER/Applications/Utilities/System Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Utilities" ]]; then
  /bin/ln -s "/Applications/Utilities" "/Users/$CURRENT_USER/Applications/Utilities/System Utilities"
fi

#################################
#インストール基本
#################################
###ここだけ変えればなんでいけるか?
STR_URL="https://go.microsoft.com/fwlink/?linkid=2093504"
###
STR_APP_NAME="Microsoft Edge"

LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/mktemp -d)
/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"

###ファイル名を取得
PKG_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
/bin/echo "PKG_FILE_NAME" "$PKG_FILE_NAME"

###ファイル名指定してダウンロード
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$PKG_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20

###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/osascript -e "tell application id \"com.microsoft.edgemac\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "$STR_APP_NAME" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (GPU)" 2>/dev/null
    /usr/bin/killall "$STR_APP_NAME Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2

### インストール(上書き)を実行する
/usr/sbin/installer -pkg "$LOCAL_TMP_DIR/$PKG_FILE_NAME" -target / -dumplog -allowUntrusted -lang ja

################################################
###設定項目
STR_BUNDLEID="com.microsoft.edgemac"
STR_APP_PATH="/Applications/Microsoft Edge.app"
###アプリケーション名を取得
STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleDisplayName)
if [ -z "$STR_APP_NAME" ]; then
  STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleName)
fi
/bin/echo "アプリケーション名:$STR_APP_NAME"
################################################
### DOCKに登録済みかゴミ箱に入れる前に調べておく
##Dockの登録数を調べる
JSON_PERSISENT_APPS=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults read com.apple.dock persistent-apps)
NUN_CNT_ITEM=$(/bin/echo "$JSON_PERSISENT_APPS" | grep -o "tile-data" | wc -l)
/bin/echo "Dock登録数:$NUN_CNT_ITEM"
##Dockの登録数だけ繰り返し
NUM_CNT=0 #カウンタ初期化
NUM_POSITION="NULL" #ポジション番号にNULL文字を入れる
###対象のバンドルIDがDockに登録されているか順番に調べる
while [ $NUM_CNT -lt "$NUN_CNT_ITEM" ]; do
  ##順番にバンドルIDを取得して
  STR_CHK_BUNDLEID=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Print:persistent-apps:$NUM_CNT:tile-data:bundle-identifier" "$HOME/Library/Preferences/com.apple.dock.plist")
  ##対象のバンドルIDだったら
  if [ "$STR_CHK_BUNDLEID" = "$STR_BUNDLEID" ]; then
    /bin/echo "DockのポジションNO: $NUM_CNT バンドルID:$STR_CHK_BUNDLEID"
    ##位置情報ポジションを記憶しておく
    NUM_POSITION=$NUM_CNT
  fi
  NUM_CNT=$((NUM_CNT + 1))
done

##結果 対象のバンドルIDが無ければ
if [ "$NUM_POSITION" = "NULL" ]; then
  /bin/echo "Dockに未登録です"
  PLIST_DICT="<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$STR_APP_PATH</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/defaults write com.apple.dock persistent-apps -array-add "$PLIST_DICT"
else
  ##すでに登録済みの場合は一旦削除
  /bin/echo "Dockの$NUM_POSITION に登録済み 削除してから同じ場所に登録しなおします"
  ##削除して
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Delete:persistent-apps:$NUM_POSITION" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###同じ内容を作成する
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:GUID integer $RANDOM$RANDOM" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 file-tile directory-tile
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-type string file-tile" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この親Dictに子要素としてtile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑子要素のtile-dataにキーと値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:showas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 2:フォルダ 41:アプリケーション 169 Launchpad とMission Control
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-type integer 41" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:displayas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:parent-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-label string $STR_APP_NAME" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:is-beta bool false" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この子要素のtile-dataに孫要素でfile-dataをDictで追加
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###値を入れていく
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLStringType integer 15" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLString string file://$STR_APP_PATH" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/bin/sudo -u "$CONSOLE_USER" /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
fi
###
/bin/echo "処理終了 DOCKを再起動します"
/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/killall "Dock"

################################################
### クリーニング ローカルドメイン
#####不要なファイルをゴミ箱に
function DO_MOVE_TO_TRASH_SUDO() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/mktemp -d "/Users/$CONSOLE_USER/.Trash/Edge.XXXXXXXX")
    /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
    /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
  fi
}
DO_MOVE_TO_TRASH_SUDO "/Library/Application Support/Microsoft/EdgeUpdater"
DO_MOVE_TO_TRASH_SUDO "/Library/Microsoft/EdgeUpdater"

################################################
### クリーニング ユーザードメイン
### 対象ファイルを起動時に削除する項目へ入れる
function DO_MOVE_TO_TRASH_USER() {
  local STR_DO_FILE_PATH="$1"
  local STR_DO_USERID="$2"

  if [ -e "$STR_DO_FILE_PATH" ]; then
    USER_TRASH_DIR=$(/usr/bin/sudo -u "$STR_DO_USERID" /usr/bin/mktemp -d "/private/tmp/Cleanup At Startup/.Trash/$STR_DO_USERID/Edge.XXXXXXXX")
    /bin/chmod 777 "$USER_TRASH_DIR"
    /bin/mv "$STR_DO_FILE_PATH" "$USER_TRASH_DIR"
  fi
}

for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/mkdir -p "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  /bin/chmod 777 "/private/tmp/Cleanup At Startup/.Trash/${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/Microsoft Edge" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.edgemac" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Caches/com.microsoft.EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft/EdgeUpdater" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/ShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}Library/Application Support/Microsoft Edge/Guest Profile" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GrShaderCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/GraphiteDawnCache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/extensions_crx_cache" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/Crashpad" "${ITEM_LIST}"
  DO_MOVE_TO_TRASH_USER "/Users/${ITEM_LIST}/Library/Application Support/Microsoft Edge/component_crx_cache" "${ITEM_LIST}"

done

exit 0


|

OpenEdgeURLs


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

#!/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 "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

###パス(ホスト)リスト
set listURLs to {"edge-urls", "about", "accessibility", "app-service-internals", "app-settings", "application-guard-internals", "apps", "attribution-internals", "augloop-internals", "autofill-internals", "blob-internals", "bluetooth-internals", "browser-essentials", "collected-cookies-dialog", "commerce-internals", "compat", "components", "connectors-internals", "crashes", "credits", "data-viewer", "device-log", "discards", "download-internals", "downloads", "edge-dlp-internals", "extensions", "extensions-internals", "favorites", "flags", "floc-internals", "gcm-internals", "gpu", "help", "histograms", "history", "history-clusters-internals", "indexeddb-internals", "inspect", "interstitials", "invalidations", "launch-source", "local-state", "mam-internals", "management", "media-engagement", "media-internals", "metrics-internals", "net-export", "net-internals", "network-errors", "newtab", "ntp-tiles-internals", "omnibox", "optimization-guide-internals", "password-manager", "password-manager-internals", "policy", "predictors", "prefs-internals", "print", "private-aggregation-internals", "process-internals", "profile-internals", "push-internals", "quota-internals", "serviceworker-internals", "settings", "signin-internals", "site-engagement", "suggest-internals", "super-resolution-popup", "sync-internals", "system", "tab-search.top-chrome", "terms", "topics-internals", "tracing", "translate-internals", "ukm", "usb-internals", "user-actions", "version", "web-app-internals", "webrtc-internals", "webrtc-logs"} as list


##############################
###ダイアログ
tell current application
  set strName to name as text
end tell
###スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to "選んでください" as text
set strPrompt to "選んでください" as text
try
  set listResponse to (choose from list listURLs with title strTitle with prompt strPrompt default items (item 1 of listURLs) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
  error "エラーしました" number -200
end try
if listResponse = {} then
  log "何も選択していない"
return "何も選択していない"
else if (item 1 of listResponse) is false then
return "キャンセルしました"
  error "キャンセルしました" number -200
else
  ##############################
  ###選択されたホスト名を順番に開く
  repeat with itemResponse in listResponse
    ###テキストに確定
    set strResponse to itemResponse as text
    ###URLコンポーネント初期化
    set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
    ###スキーム を追加
(ocidURLComponents's setScheme:("edge"))
    ###パスを追加(setPathじゃないよ)
(ocidURLComponents's setHost:(strResponse))
    set ocidTagURL to ocidURLComponents's |URL|
    set strTagURL to ocidTagURL's absoluteString() as text
    tell application "Microsoft Edge"
      activate
      tell front window
set objNewTab to make new tab
tell objNewTab to set URL to strTagURL
      end tell
    end tell
    
  end repeat
end if



|

[headless]PDFで保存


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

#!/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 "AppKit"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()

###アプリケーションのバンドルID
set strBundleID to "com.microsoft.edgemac"
###エラー処理
tell application id strBundleID
  set numWindow to (count of every window) as integer
end tell
if numWindow = 0 then
return "Windowが無いので処理できません"
end if


###URLとタイトルを取得
tell application "Microsoft Edge"
  tell front window
    tell active tab
      activate
      set strURL to URL as text
      set strTITLE to title as text
    end tell
  end tell
end tell
##########################################
### ホスト名 -->保存先ディレクトリ名
##########################################
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set ocidHostName to ocidURL's |host|()

##########################################
### タイトル→ファイル名
##########################################
###Stringsに格納して
set ocidTITLE to refMe's NSString's stringWithString:(strTITLE)
set numTitleLength to ocidTITLE's |length|() as integer
###ファイル名は14文字にする例
if numTitleLength ≤ 13 then
  set strBaseFileName to doGetDateNo("yyyyMMddhhmmss")
else
  set ocidRange to refMe's NSMakeRange(0, 14)
  set ocidBaseFileName to ocidTITLE's substringWithRange:(ocidRange)
  set strBaseFileName to ocidBaseFileName as text
end if
###ファイル名
set strSaveFileName to (strBaseFileName & ".pdf") as text
##########################################
#### アプリケーションのパス
##########################################

set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
end if
if ocidAppPathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
  set strAppPath to POSIX path of aliasAppApth as text
  set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
  set strAppPath to strAppPathStr's stringByStandardizingPath()
  set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
end if
set ocidAppBinPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/MacOS/Microsoft Edge")
set strAppBinPath to ocidAppBinPathURL's |path|() as text

##########################
### PDF保存先
##########################
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(ocidHostName)
###保存先作っておく
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##########################
###  PDFファイル
##########################
set ocidPdfFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
set strPdfFilePath to ocidPdfFilePathURL's |path|() as text


##########################################
####PDFをプリント
##########################################
set strCommandText to ("\"" & strAppBinPath & "\" --headless --disable-gpu --print-to-pdf=\"" & strPdfFilePath & "\" \"" & strURL & "\" --margin=0 --no-header --no-footer --no-margins --page-size=A4")
do shell script strCommandText

set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
###Finderで開く
tell application "Finder"
  open aliasSaveDirPath
end tell
###プレビューで開く
tell application id "com.apple.Preview"
  open (POSIX file strPdfFilePath as alias)
end tell


##########################################
####日付情報の取得
##########################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to refMe's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"en_US")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom