Created
March 28, 2025 14:40
-
-
Save taross-f/ce0d9b08bf0eedfefb9927614fca9150 to your computer and use it in GitHub Desktop.
mac migration
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 | |
# チェック: 引数が指定されているか | |
if [ $# -eq 0 ]; then | |
echo "使用方法: $0 <設定ファイルパス>" | |
exit 1 | |
fi | |
# 設定ファイルパス | |
SETTINGS_FILE="$1" | |
# チェック: ファイルが存在するか | |
if [ ! -f "$SETTINGS_FILE" ]; then | |
echo "エラー: 指定されたファイル '$SETTINGS_FILE' が見つかりません。" | |
exit 1 | |
fi | |
# 区切り線を表示する関数 | |
print_section() { | |
echo "" | |
echo "----------------------------------------" | |
echo "## $1" | |
echo "----------------------------------------" | |
echo "" | |
} | |
# 設定を適用する関数 | |
apply_settings() { | |
local section=$1 | |
print_section "[$section] の設定を適用中..." | |
} | |
# Dock設定を適用 | |
apply_dock_settings() { | |
print_section "Dock設定を適用中" | |
# ファイルからDock設定セクションを抽出 | |
local dock_settings=$(sed -n '/^## Dock設定$/,/^##/p' "$SETTINGS_FILE" | grep -v "^##" | grep -v "^----") | |
# 自動的に隠す設定 | |
if echo "$dock_settings" | grep -q "autohide = 1"; then | |
echo "Dockを自動的に隠す設定を適用します" | |
defaults write com.apple.dock autohide -bool true | |
elif echo "$dock_settings" | grep -q "autohide = 0"; then | |
echo "Dockを常に表示する設定を適用します" | |
defaults write com.apple.dock autohide -bool false | |
fi | |
# Dockのサイズ設定 | |
local tilesize=$(echo "$dock_settings" | grep "tilesize =" | sed 's/.*tilesize = \([0-9]*\);.*/\1/') | |
if [ ! -z "$tilesize" ]; then | |
echo "Dockのサイズを $tilesize に設定します" | |
defaults write com.apple.dock tilesize -int "$tilesize" | |
fi | |
# 拡大機能の設定 | |
if echo "$dock_settings" | grep -q "magnification = 1"; then | |
echo "Dock拡大機能を有効にします" | |
defaults write com.apple.dock magnification -bool true | |
elif echo "$dock_settings" | grep -q "magnification = 0"; then | |
echo "Dock拡大機能を無効にします" | |
defaults write com.apple.dock magnification -bool false | |
fi | |
} | |
# Finder設定を適用 | |
apply_finder_settings() { | |
print_section "Finder設定を適用中" | |
# ファイルからFinder設定セクションを抽出 | |
local finder_settings=$(sed -n '/^## Finder設定$/,/^##/p' "$SETTINGS_FILE" | grep -v "^##" | grep -v "^----") | |
# 隠しファイルを表示する設定 | |
if echo "$finder_settings" | grep -q "AppleShowAllFiles = 1"; then | |
echo "隠しファイルを表示する設定を適用します" | |
defaults write com.apple.finder AppleShowAllFiles -bool true | |
elif echo "$finder_settings" | grep -q "AppleShowAllFiles = 0"; then | |
echo "隠しファイルを非表示にする設定を適用します" | |
defaults write com.apple.finder AppleShowAllFiles -bool false | |
fi | |
# ファイル拡張子を表示する設定 | |
if echo "$finder_settings" | grep -q "AppleShowAllExtensions = 1"; then | |
echo "すべてのファイル拡張子を表示する設定を適用します" | |
defaults write com.apple.finder AppleShowAllExtensions -bool true | |
elif echo "$finder_settings" | grep -q "AppleShowAllExtensions = 0"; then | |
echo "ファイル拡張子を非表示にする設定を適用します" | |
defaults write com.apple.finder AppleShowAllExtensions -bool false | |
fi | |
} | |
# スクリーンショット設定を適用 | |
apply_screenshot_settings() { | |
print_section "スクリーンショット設定を適用中" | |
# ファイルからスクリーンショット設定セクションを抽出 | |
local screenshot_settings=$(sed -n '/^## スクリーンショット設定$/,/^##/p' "$SETTINGS_FILE" | grep -v "^##" | grep -v "^----") | |
# スクリーンショットの保存先 | |
local location=$(echo "$screenshot_settings" | grep "location =" | sed 's/.*location = "\(.*\)";.*/\1/') | |
if [ ! -z "$location" ]; then | |
echo "スクリーンショットの保存先を $location に設定します" | |
defaults write com.apple.screencapture location -string "$location" | |
fi | |
# スクリーンショットのフォーマット | |
local type=$(echo "$screenshot_settings" | grep "type =" | sed 's/.*type = "\(.*\)";.*/\1/') | |
if [ ! -z "$type" ]; then | |
echo "スクリーンショットのフォーマットを $type に設定します" | |
defaults write com.apple.screencapture type -string "$type" | |
fi | |
} | |
# キーボード設定を適用 | |
apply_keyboard_settings() { | |
print_section "キーボード設定を適用中" | |
# キーのリピート速度 | |
local key_repeat=$(grep "KeyRepeat = " "$SETTINGS_FILE" | head -1 | sed 's/.*KeyRepeat = \([0-9]*\).*/\1/') | |
if [ ! -z "$key_repeat" ]; then | |
echo "キーのリピート速度を $key_repeat に設定します" | |
defaults write -g KeyRepeat -int "$key_repeat" | |
fi | |
# キーのリピート開始までの時間 | |
local initial_repeat=$(grep "InitialKeyRepeat = " "$SETTINGS_FILE" | head -1 | sed 's/.*InitialKeyRepeat = \([0-9]*\).*/\1/') | |
if [ ! -z "$initial_repeat" ]; then | |
echo "キーのリピート開始までの時間を $initial_repeat に設定します" | |
defaults write -g InitialKeyRepeat -int "$initial_repeat" | |
fi | |
} | |
# ユーザーインターフェース設定を適用 | |
apply_ui_settings() { | |
print_section "ユーザーインターフェース設定を適用中" | |
# ダークモード設定 | |
local interface_style=$(grep "AppleInterfaceStyle = " "$SETTINGS_FILE" | head -1 | sed 's/.*AppleInterfaceStyle = \(.*\).*/\1/') | |
if [ "$interface_style" = "Dark" ]; then | |
echo "ダークモードを有効にします" | |
defaults write -g AppleInterfaceStyle -string "Dark" | |
elif [ "$interface_style" = "Light" ] || [ -z "$interface_style" ]; then | |
echo "ライトモードを有効にします" | |
defaults delete -g AppleInterfaceStyle 2>/dev/null | |
fi | |
# 透明度設定 | |
if grep -q "AppleReduceTransparency = 1" "$SETTINGS_FILE"; then | |
echo "透明効果を削減する設定を適用します" | |
defaults write -g AppleReduceTransparency -bool true | |
elif grep -q "AppleReduceTransparency = 0" "$SETTINGS_FILE"; then | |
echo "透明効果を標準に設定します" | |
defaults write -g AppleReduceTransparency -bool false | |
fi | |
} | |
# メイン処理 | |
echo "macOS設定を適用します" | |
echo "設定ファイル: $SETTINGS_FILE" | |
# 各種設定の適用 | |
apply_dock_settings | |
apply_finder_settings | |
apply_screenshot_settings | |
apply_keyboard_settings | |
apply_ui_settings | |
# 設定の反映には再起動が必要 | |
print_section "設定の適用が完了しました" | |
echo "一部の設定は、Finder、Dock、その他のアプリケーションを再起動するまで反映されない場合があります。" | |
echo "以下のコマンドを実行して変更を適用できます:" | |
echo "killall Finder" | |
echo "killall Dock" | |
echo "" | |
echo "すべての設定を完全に反映させるには、システムの再起動をお勧めします。" | |
# 設定を適用するか確認 | |
read -p "Finder と Dock を再起動して設定を適用しますか? (y/n): " restart_choice | |
if [[ $restart_choice =~ ^[Yy]$ ]]; then | |
echo "Finder と Dock を再起動中..." | |
killall Finder | |
killall Dock | |
echo "完了しました。" | |
fi |
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 | |
# 結果を保存するファイルのパス | |
OUTPUT_FILE="$HOME/Desktop/mac_system_settings_$(date +%Y%m%d_%H%M%S).txt" | |
# タイトルとタイムスタンプを出力 | |
echo "# macOS システム設定情報" > "$OUTPUT_FILE" | |
echo "# 取得日時: $(date)" >> "$OUTPUT_FILE" | |
echo "# ホスト名: $(hostname)" >> "$OUTPUT_FILE" | |
echo "# macOSバージョン: $(sw_vers -productVersion)" >> "$OUTPUT_FILE" | |
echo "" >> "$OUTPUT_FILE" | |
# 区切り線を表示する関数 | |
print_section() { | |
echo "" >> "$OUTPUT_FILE" | |
echo "----------------------------------------" >> "$OUTPUT_FILE" | |
echo "## $1" >> "$OUTPUT_FILE" | |
echo "----------------------------------------" >> "$OUTPUT_FILE" | |
echo "" >> "$OUTPUT_FILE" | |
} | |
# Dock設定 | |
print_section "Dock設定" | |
defaults read com.apple.dock >> "$OUTPUT_FILE" | |
# Finder設定 | |
print_section "Finder設定" | |
defaults read com.apple.finder >> "$OUTPUT_FILE" | |
# Mission Control設定 | |
print_section "Mission Control設定" | |
defaults read com.apple.dock wvous-corner-actions 2>/dev/null >> "$OUTPUT_FILE" | |
# セキュリティとプライバシー設定 | |
print_section "セキュリティ設定" | |
echo "### ファイアウォール状態" >> "$OUTPUT_FILE" | |
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate >> "$OUTPUT_FILE" | |
# エネルギー設定 | |
print_section "エネルギー設定" | |
pmset -g >> "$OUTPUT_FILE" | |
# キーボード設定 | |
print_section "キーボード設定" | |
defaults read com.apple.HIToolbox >> "$OUTPUT_FILE" | |
defaults read -g KeyRepeat >> "$OUTPUT_FILE" | |
defaults read -g InitialKeyRepeat >> "$OUTPUT_FILE" | |
# トラックパッド設定 | |
print_section "トラックパッド設定" | |
defaults read com.apple.driver.AppleBluetoothMultitouch.trackpad >> "$OUTPUT_FILE" | |
defaults read com.apple.AppleMultitouchTrackpad >> "$OUTPUT_FILE" | |
# スクリーンショット設定 | |
print_section "スクリーンショット設定" | |
defaults read com.apple.screencapture >> "$OUTPUT_FILE" | |
# ユーザーインターフェース設定 | |
print_section "ユーザーインターフェース設定" | |
defaults read -g AppleInterfaceStyle 2>/dev/null >> "$OUTPUT_FILE" | |
defaults read -g AppleReduceTransparency 2>/dev/null >> "$OUTPUT_FILE" | |
# Login Items (ログイン項目) | |
print_section "ログイン項目" | |
osascript -e 'tell application "System Events" to get the name of every login item' >> "$OUTPUT_FILE" | |
# 完了メッセージ | |
echo "" >> "$OUTPUT_FILE" | |
echo "# 設定情報の取得が完了しました" >> "$OUTPUT_FILE" | |
echo "システム設定情報を $OUTPUT_FILE に保存しました。" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment