20260319

[com.apple.SoftwareUpdate]SplatEnabled(バックグラウンドセキュリティ改善)


[com.apple.SoftwareUpdate]SplatEnabled(バックグラウンドセキュリティ改善)


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

com.apple.SoftwareUpdate.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005com.apple.SoftwareUpdate設定の変更サンプル
006SplatEnabled バックグラウンドセキュリティを有効に
007AutomaticDownload 許可なしダウンロードを無効に
008PostSuccessfulMinorUpdatePostLogOutNotification 通知を無効に
009restrict-software-update-require-admin-to-install
010アップデートには管理者権限が必要を有効に
011com.cocolog-nifty.quicktimer.icefloe *)
012----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
013use AppleScript version "2.8"
014use scripting additions
015####################################
016#SplatEnabled
017#現在の設定を確認
018set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled") as text
019set strStdOut to (do shell script strCmd) as text
020#戻り値で分岐
021if strStdOut is "1" then
022   #設定変更
023   set strCmd to ("/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled -bool false") as text
024   do shell script strCmd
025   delay 0.25
026   #確認に出力
027   set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled") as text
028   set strStdOut to (do shell script strCmd) as text
029end if
030if strStdOut is "0" then
031   log "SplatEnabledは無効になりました"
032else
033   log "システム担当にお問い合わせください"
034end if
035
036####################################
037#AutomaticDownload
038#現在の設定を確認
039set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticDownload") as text
040set strStdOut to (do shell script strCmd) as text
041#戻り値で分岐
042if strStdOut is "1" then
043   #設定変更
044   set strCmd to ("/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticDownload -bool false") as text
045   do shell script strCmd
046   delay 0.25
047   #確認に出力
048   set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticDownload") as text
049   set strStdOut to (do shell script strCmd) as text
050end if
051if strStdOut is "0" then
052   log "AutomaticDownloadは無効になりました"
053else
054   log "システム担当にお問い合わせください"
055end if
056####################################
057#PostSuccessfulMinorUpdatePostLogOutNotification
058#現在の設定を確認
059set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist PostSuccessfulMinorUpdatePostLogOutNotification") as text
060set strStdOut to (do shell script strCmd) as text
061#戻り値で分岐
062if strStdOut is "1" then
063   #設定変更
064   set strCmd to ("/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist PostSuccessfulMinorUpdatePostLogOutNotification -bool false") as text
065   do shell script strCmd
066   delay 0.25
067   #確認に出力
068   set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist PostSuccessfulMinorUpdatePostLogOutNotification") as text
069   set strStdOut to (do shell script strCmd) as text
070end if
071if strStdOut is "0" then
072   log "PostSuccessfulMinorUpdatePostLogOutNotificationは無効になりました"
073else
074   log "システム担当にお問い合わせください"
075end if
076####################################
077#PostSuccessfulMinorUpdatePostLogOutNotification
078#現在の設定を確認
079set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist restrict-software-update-require-admin-to-install") as text
080set strStdOut to (do shell script strCmd) as text
081#戻り値で分岐
082if strStdOut is "0" then
083   #設定変更
084   set strCmd to ("/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist restrict-software-update-require-admin-to-install -bool true") as text
085   do shell script strCmd
086   delay 0.25
087   #確認に出力
088   set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist restrict-software-update-require-admin-to-install") as text
089   set strStdOut to (do shell script strCmd) as text
090end if
091if strStdOut is "1" then
092   log "restrict-software-update-require-admin-to-installは有効になりました"
093else
094   log "システム担当にお問い合わせください"
095end if
AppleScriptで生成しました

com.apple.SoftwareUpdate.bash

サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#set -x
004#################################################
005###管理者インストールしているか?チェック
006USER_WHOAMI=$(/usr/bin/whoami)
007/bin/echo "実行ユーザー(whoami): ${USER_WHOAMI}"
008if [ "${USER_WHOAMI}" != "root" ]; then
009  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
010  /bin/echo "sudo で実行してください"
011  ### path to me
012  SCRIPT_PATH="${BASH_SOURCE[0]}"
013  /bin/echo "/usr/bin/sudo \"${SCRIPT_PATH}\""
014  /bin/echo "↑を実行してください"
015  ###実行しているユーザー名
016  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
017  /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
018  /bin/echo "------"
019  /bin/echo "続行しますか?"
020  /bin/echo "半角『N』で処理を中断して終了します"
021  /bin/echo "半角『Y』でターミナルの新規Windowから実行します (Y/N)"
022  /bin/echo "ターミナル上に(Y/N)のどちらか入力してリターン(改行キー)を実行してください"
023  read -r USER_RESPONSE
024  case "${USER_RESPONSE}" in
025  y | yes | Y)
026    /bin/echo "ターミナルの新規Windowから実行します"
027    /usr/bin/osascript -e "tell application \"Terminal\" to do script \"/usr/bin/sudo \\\"${SCRIPT_PATH}\\\"\""
028    /usr/bin/osascript -e "tell application \"Terminal\" to activate"
029    ;;
030  n | no | N)
031    /bin/echo "処理を中断してキャンセルします"
032    exit 0
033    ;;
034  esac
035  exit 1
036else
037  ###実行しているユーザー名
038  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
039  /bin/echo "コンソールユーザー(scutil): ${CONSOLE_USER}"
040  ###実行しているユーザー名
041  HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
042  /bin/echo "実行ユーザー(HOME): ${HOME_USER}"
043  ###logname
044  LOGIN_NAME=$(/usr/bin/logname)
045  /bin/echo "ログイン名(logname): ${LOGIN_NAME}"
046  ###UID
047  USER_NAME=$(/usr/bin/id -un)
048  /bin/echo "ユーザー名(id): ${USER_NAME}"
049  ###STAT
050  STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
051  /bin/echo "STAT_USR(console): ${STAT_USR}"
052fi
053#ここから本処理
054##############################
055#
056STR_PLIST_PATH="/Library/Managed Preferences/com.apple.SoftwareUpdate.plist"
057if [[ -f ${STR_PLIST_PATH} ]]; then
058  echo "MDMで設定されていますので変更しても反映されない可能性があります"
059fi
060STR_PLIST_PATH="/Library/Managed Preferences/${STAT_USR}/com.apple.SoftwareUpdate.plist"
061if [[ -f ${STR_PLIST_PATH} ]]; then
062  echo "MDMで設定されていますので変更しても反映されない可能性があります"
063fi
064
065##############################
066#SplatEnabled
067STR_RESPONSE=$(/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled)
068if [ "${STR_RESPONSE}" == "0" ]; then
069/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled -bool false
070else
071/usr/bin/sudo /usr/bin/defaults write  /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled -bool true
072fi
073STR_RESPONSE=$(/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled)
074/bin/echo "SplatEnabled: ${STR_RESPONSE}"
075/bin/echo "0: 0ならFALSE NO 無効"
076/bin/echo "1: 0ならTRUE YES 有効"
077exit 0
AppleScriptで生成しました