ブラウザのプロファイルを使い分けるために。
成果物
インストールと実行
git clone https://github.com/ytyaru/Python.ChromiumProfile.20190420172141 cd Python.ChromiumProfile.20190420172141/src
python3 ChromiumProfileCommand.py tsv
コマンド概要
メインコマンド引数
引数 | 意味 |
---|---|
-f |
設定ファイルパスが~/.config/chromium/Local State 以外なら指定する |
サブコマンドと引数
サブコマンド | 引数 | 意味 |
---|---|---|
tsv |
TSV形式で出力する | |
list |
-d |
ディレクトリ名一覧(改行区切り) |
list |
-u |
ユーザ名一覧(改行区切り) |
get |
-d ユーザ名 |
対応するディレクトリ名 |
get |
-u ディレクトリ名 |
対応するユーザ名 |
get |
-l |
最後に使用したディレクトリ名 |
使用例
プロファイルは以下とする。
ディレクトリ名 | ユーザ名 |
---|---|
Default |
default |
Profile 1 |
work |
Profile 2 |
life |
TSV形式。
python3 ChromiumProfileCommand.py tsv
Default default Profile 1 work Profile 2 life
ディレクトリ名一覧。(辞書順)
python3 ChromiumProfileCommand.py list -d
Default Profile 1 Profile 2
ユーザ名一覧。(ディレクトリ名の辞書順)
python3 ChromiumProfileCommand.py list -u
default work life
ディレクトリ名からユーザ名を取得する。
python3 ChromiumProfileCommand.py get -u 'Profile 2'
life
ユーザ名からディレクトリ名を取得する。
python3 ChromiumProfileCommand.py get -d 'life'
Profile 2
最後に使用したユーザ名を取得する。
python3 ChromiumProfileCommand.py get -l
(最後に終了したプロファイルのディレクトリ名))
設定ファイルパスが~/.config/chromium/Local State
以外の場所なら-f
で指定する。(サブコマンドの前)
python3 ChromiumProfileCommand.py -f /tmp/LocalState.json get -d 'life'
おまけ
selector.sh
zenity
コマンドを用いてプロファイル選択GUIを表示する。
Chromiumプロファイルについて
プロファイルはブックマークやパスワードなどを別々に保存できる機能である。
- プロファイルを作ると勝手に「Profile ?」という名前のディレクトリが作られる
- 好きなユーザ名を付与できる
- ブラウザのユーザ一覧にユーザ名が表示される
- 選んだユーザのプロファイル設定でブラウザを起動する
プロファイル情報の在り処
~/.config/chromium/Local State
.profile.info_cache.name
JSON整形
python3 -m json.tool < "${HOME}/.config/chromium/Local State"
パスを目視で確認するために。
ディレクトリ名
Default
Profile 1
(2,3,4...)
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
- python 3.5.3
$ uname -a Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux