LoginSignup
1
1

More than 5 years have passed since last update.

miのモード設定をバックアップするAppleScript

Last updated at Posted at 2013-12-05

OS Xのいろいろな設定をバックアップするツールのモジュールの一つとしてつくったもの。

準備

以下のAppleScriptと簡単なシェルスクリプトを同じフォルダに配置します。

mode.scpt
#!/usr/bin/env osascript

tell application "/Applications/mi.app"
  activate
  delay 1.0
  activate
end tell

tell application "System Events"
  tell process "mi"
    click menu item "モード設定..." of menu "mi" of menu bar item "mi" of menu bar 1
    delay 0.2
    tell tab group 1 of window "モード設定"
      click radio button "管理"
      delay 0.2
      click button "モード設定全体のバックアップ保存" of group 1
    end tell
  end tell
end tell

tell application "Finder"
  activate
  delay 0.5
  set output to (posix path of (the selection as alias))
  return output
end tell
mode.sh
#!/bin/sh

mi_config_path=`/usr/bin/env osascript ./mode.scpt`
sleep 0.5
mv "$mi_config_path" "$1"

実行

次に以下のようなコマンドをタイプします。

$ chmod +x mode.sh
$ ./mode.sh mode-backup.zip

すると、カレントディレクトリに mode-backup.zip というアーカイブが書き出されます。このファイルがバックアップデータなので、保管しておきます。

なにをしているのか

  1. mode.scptはmiを起動し、モード設定のバックアップを書き出す処理を実行させる
  2. mode.shは書き出されたアーカイブをFinder経由で取得し、カレントディレクトリに移動させる
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1