[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 | (* |
| 005 | com.apple.SoftwareUpdate設定の変更サンプル |
| 006 | SplatEnabled バックグラウンドセキュリティを有効に |
| 007 | AutomaticDownload 許可なしダウンロードを無効に |
| 008 | PostSuccessfulMinorUpdatePostLogOutNotification 通知を無効に |
| 009 | restrict-software-update-require-admin-to-install |
| 010 | アップデートには管理者権限が必要を有効に |
| 011 | com.cocolog-nifty.quicktimer.icefloe *) |
| 012 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 013 | use AppleScript version "2.8" |
| 014 | use scripting additions |
| 015 | #################################### |
| 016 | #SplatEnabled |
| 017 | #現在の設定を確認 |
| 018 | set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled") as text |
| 019 | set strStdOut to (do shell script strCmd) as text |
| 020 | #戻り値で分岐 |
| 021 | if 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 |
| 029 | end if |
| 030 | if strStdOut is "0" then |
| 031 | log "SplatEnabledは無効になりました" |
| 032 | else |
| 033 | log "システム担当にお問い合わせください" |
| 034 | end if |
| 035 |
|
| 036 | #################################### |
| 037 | #AutomaticDownload |
| 038 | #現在の設定を確認 |
| 039 | set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist AutomaticDownload") as text |
| 040 | set strStdOut to (do shell script strCmd) as text |
| 041 | #戻り値で分岐 |
| 042 | if 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 |
| 050 | end if |
| 051 | if strStdOut is "0" then |
| 052 | log "AutomaticDownloadは無効になりました" |
| 053 | else |
| 054 | log "システム担当にお問い合わせください" |
| 055 | end if |
| 056 | #################################### |
| 057 | #PostSuccessfulMinorUpdatePostLogOutNotification |
| 058 | #現在の設定を確認 |
| 059 | set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist PostSuccessfulMinorUpdatePostLogOutNotification") as text |
| 060 | set strStdOut to (do shell script strCmd) as text |
| 061 | #戻り値で分岐 |
| 062 | if 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 |
| 070 | end if |
| 071 | if strStdOut is "0" then |
| 072 | log "PostSuccessfulMinorUpdatePostLogOutNotificationは無効になりました" |
| 073 | else |
| 074 | log "システム担当にお問い合わせください" |
| 075 | end if |
| 076 | #################################### |
| 077 | #PostSuccessfulMinorUpdatePostLogOutNotification |
| 078 | #現在の設定を確認 |
| 079 | set strCmd to ("/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist restrict-software-update-require-admin-to-install") as text |
| 080 | set strStdOut to (do shell script strCmd) as text |
| 081 | #戻り値で分岐 |
| 082 | if 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 |
| 090 | end if |
| 091 | if strStdOut is "1" then |
| 092 | log "restrict-software-update-require-admin-to-installは有効になりました" |
| 093 | else |
| 094 | log "システム担当にお問い合わせください" |
| 095 | end if |
| AppleScriptで生成しました |
|---|
com.apple.SoftwareUpdate.bash
サンプルコード
サンプルソース(参考)| 行番号 | ソース |
|---|
| 001 | #!/bin/bash |
|---|
| 002 | #com.cocolog-nifty.quicktimer.icefloe |
|---|
| 003 | #set -x |
|---|
| 004 | ################################################# |
|---|
| 005 | ###管理者インストールしているか?チェック |
|---|
| 006 | USER_WHOAMI=$(/usr/bin/whoami) |
|---|
| 007 | /bin/echo "実行ユーザー(whoami): ${USER_WHOAMI}" |
|---|
| 008 | if [ "${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 |
|---|
| 036 | else |
|---|
| 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}" |
|---|
| 052 | fi |
|---|
| 053 | #ここから本処理 |
|---|
| 054 | ############################## |
|---|
| 055 | # |
|---|
| 056 | STR_PLIST_PATH="/Library/Managed Preferences/com.apple.SoftwareUpdate.plist" |
|---|
| 057 | if [[ -f ${STR_PLIST_PATH} ]]; then |
|---|
| 058 | echo "MDMで設定されていますので変更しても反映されない可能性があります" |
|---|
| 059 | fi |
|---|
| 060 | STR_PLIST_PATH="/Library/Managed Preferences/${STAT_USR}/com.apple.SoftwareUpdate.plist" |
|---|
| 061 | if [[ -f ${STR_PLIST_PATH} ]]; then |
|---|
| 062 | echo "MDMで設定されていますので変更しても反映されない可能性があります" |
|---|
| 063 | fi |
|---|
| 064 | |
|---|
| 065 | ############################## |
|---|
| 066 | #SplatEnabled |
|---|
| 067 | STR_RESPONSE=$(/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled) |
|---|
| 068 | if [ "${STR_RESPONSE}" == "0" ]; then |
|---|
| 069 | /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled -bool false |
|---|
| 070 | else |
|---|
| 071 | /usr/bin/sudo /usr/bin/defaults write /Library/Preferences/com.apple.SoftwareUpdate.plist SplatEnabled -bool true |
|---|
| 072 | fi |
|---|
| 073 | STR_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 有効" |
|---|
| 077 | exit 0 |
|---|
| AppleScriptで生成しました |
|---|