Last active
December 18, 2025 13:10
-
-
Save Miyu-dev/8ab8fe2cd25e73e064df61f8a4d6a72a to your computer and use it in GitHub Desktop.
macOS向けGoogle Chrome (Stable) の更新を促すためのスクリプト for Intune
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ポップアップのタイトルとボタン | |
| TITLE="情報システム部よりお知らせ" | |
| BTN_OPEN="更新画面を開く" | |
| BTN_LATER="あとで" | |
| # 表示するメッセージ | |
| MESSAGE_TEMPLATE="Google Chromeのアップデートが利用可能 | |
| お使いのバージョン: CURRENT_VERSION_PLACEHOLDER | |
| 更新後のバージョン: TARGET_VERSION_PLACEHOLDER | |
| 「BTN_OPEN_PLACEHOLDER」を押すと更新画面が開きます。 | |
| 更新の確認後、Chromeの再起動を行ってください。" | |
| # ------------------------ | |
| # Chromeがインストール先にあるか確認 | |
| CHROME_APP="/Applications/Google Chrome.app" | |
| if [ ! -d "$CHROME_APP" ]; then | |
| exit 0 | |
| fi | |
| # --- 最新バージョンの取得 --- | |
| API_URL="https://versionhistory.googleapis.com/v1/chrome/platforms/mac/channels/stable/versions" | |
| # "version": "XXX" のパターンから中身だけを抽出 | |
| # "version"の後に任意のスペース( *)を許容し、ダブルクォートの中身をキャプチャ | |
| TARGET_VERSION=$(curl -s "$API_URL" | grep '"version":' | head -n 1 | sed -E 's/.*"version": *"([^"]*)".*/\1/') | |
| echo "TARGET_VERSION: $TARGET_VERSION" | |
| if [ -z "$TARGET_VERSION" ]; then | |
| echo "Failed to fetch latest Chrome version from API" | |
| exit 1 | |
| fi | |
| # --- バージョンの取得 --- | |
| CURRENT_VERSION=$(defaults read "$CHROME_APP/Contents/Info.plist" CFBundleShortVersionString) | |
| # --- バージョンチェック --- | |
| if [ "$CURRENT_VERSION" == "$TARGET_VERSION" ]; then | |
| echo "No action needed" | |
| exit 0 | |
| fi | |
| # --- メッセージの組み立て --- | |
| MESSAGE="${MESSAGE_TEMPLATE//CURRENT_VERSION_PLACEHOLDER/$CURRENT_VERSION}" | |
| MESSAGE="${MESSAGE//TARGET_VERSION_PLACEHOLDER/$TARGET_VERSION}" | |
| MESSAGE="${MESSAGE//BTN_OPEN_PLACEHOLDER/$BTN_OPEN}" | |
| # --- ポップアップ表示 --- | |
| RESULT=$(osascript <<EOF | |
| display dialog "$MESSAGE" with title "$TITLE" buttons {"$BTN_LATER", "$BTN_OPEN"} default button "$BTN_OPEN" with icon note | |
| EOF | |
| ) | |
| # --- ボタン判定 --- | |
| if echo "$RESULT" | grep -q "button returned:$BTN_OPEN"; then | |
| open -a "Google Chrome" "chrome://settings/help" | |
| else | |
| echo "User selected Later." | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment