GNOMEで時刻表示形式を変更する
概要
GNOMEはUnixライクなOSで動作するオープンソースのデスクトップ環境です. 現在, Ubuntu や CentOS などの多くのLinuxディストリビューションで標準のデスクトップ環境として採用されています.
今回はGNOMEにおいて時刻表示形式をどのように変更するかを調べました.
環境
以下のような環境で検証しました.
$ cat /etc/os-release NAME="Ubuntu" VERSION="18.04.4 LTS (Bionic Beaver)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 18.04.4 LTS" VERSION_ID="18.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=bionic UBUNTU_CODENAME=bionic $ gnome-shell --version GNOME Shell 3.28.4
設定 (Settings)
設定 (Settings) からは表示形式を 24時制/12時制 のいずれかに変更することができます.
この変更画面にたどり着くのも少し面倒なので手順を述べます.
- 設定 (Settings) を開く. (左上の アクティビティ (Activity) ボタンを押して, Settings と入力すると開けます)
- サイドバーの一番下の
詳細 (Details)
ボタンを押す. - サイドバーの
日付と時刻 (Date & Time)
を押す.
Tweaks
GNOMEのUIのカスタマイズをGUIから行える Tweaks というツールがあります.
下記のコマンドでインストールできます.
$ sudo apt install gnome-tweaks
Tweaks のトップバー (topbar)
という項目から日付や秒を表示するかどうかを選択できます.
Clock Override
Clock Override
というGNOMEの拡張機能により, ステータスバー(トップバー)の時刻表示形式を変更することができます.
インストールはブラウザ経由で行う方法とUbuntuソフトウェアセンターから方法があります.
Ubuntu ソフトウェアセンターまたは https://extensions.gnome.org の検索バーに Clock Override
と入力して適当にボタンを押せばインストールできます.
拡張機能は Tweaks の拡張機能/Extension という項目から設定できます.
Clock Override
を使うことで, トップバーに表示される時計の時刻表示形式は自由に変更できます.
Datetime Format
Datetime Format
というGNOMEの拡張機能により, トップバーおよび日付メニューの時刻表示形式を変更することができます.
文字コードに日本語を含むものを指定すると, 設定自体はできるのですが, それ以降この拡張機能の設定をしようとすると以下のようなエラーが出ます.
Error: Failed to convert locale string to UTF8: 変換する入力に無効なバイトの並びがあります Stack trace: dateTimeFormat@/home/kira/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com/Utilities.js:15:20 create/updatePreview@/home/kira/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com/FormatTarget.js:49:25 create@/home/kira/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com/FormatTarget.js:55:2 buildPrefsWidget/<@/home/kira/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com/prefs.js:136:61 buildPrefsWidget@/home/kira/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com/prefs.js:136:2 _selectExtension@resource:///org/gnome/shell/extensionPrefs/main.js:91:22 wrapper@resource:///org/gnome/gjs/modules/_legacy.js:82:22 _onCommandLine@resource:///org/gnome/shell/extensionPrefs/main.js:243:17 wrapper@resource:///org/gnome/gjs/modules/_legacy.js:82:22 main@resource:///org/gnome/shell/extensionPrefs/main.js:397:5 @<main>:1:43
どうやら Unicode をサポートしていないようです. Github に issue が立ってました.
GSettings
GUIによる Datetime Format
の設定ができなくなったので,
GSettings
を使って Datetime Format
の値の設定をしてみます.
GNOMEにおいて日付の表示形式を含むユーザの設定情報は dconf
という設定システムにより管理されています.
GSettings
は dconf
のフロントツールで, 設定を行うためのAPI群です.
gsettings
コマンドにより, ユーザ設定の編集を行うことができます.
man gsettigns
と言うコマンドを叩くとマニュアルが表示されます.
以下のコマンドで Datetime Format
の key をリスト表示させてみます.
$ gsettings --schemadir ~/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com list-keys org.gnome.shell.extensions.datetime-format datemenuday-format statusbar-format statusbar-toggle datemenudate-toggle datemenudate-format datemenuday-toggle
statusbar-format
の値を変更することでステータスバー (トップバー) の時刻表示形式を変えてみます.
日付の書式文字列は man date
とするとマニュアルを参照できます.
以下のコマンドで, statusbar-format
の値を %m月%d日(%a) %H:%M
に変更できます.
$ gsettings --schemadir ~/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com set org.gnome.shell.extensions.datetime-format statusbar-format "%m月%d日(%a) %H:%M"
以下のコマンドで, datemenuday-format
の値を %H:%M:%S
に変更できます.
$ gsettings --schemadir ~/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com set org.gnome.shell.extensions.datetime-format datemenuday-format "%H:%M:%S"
以下のコマンドで, datemenudate-format
の値を %Y年%m月%d日(%a)
に変更できます.
$ gsettings --schemadir ~/.local/share/gnome-shell/extensions/datetime-format@Daniel-Khodabakhsh.github.com set org.gnome.shell.extensions.datetime-format datemenudate-format "%Y年%m月%d日(%a)"
これらの設定により時刻表示部分は以下のような外観となりました. カレンダーの月の値の表示の下部が少し隠れているのが気になりますが概ね良さそうです.
参考文献
- https://en.wikipedia.org/wiki/GNOME
- https://help.ubuntu.com/stable/ubuntu-help/clock-set.html.en
- http://ubuntuhandbook.org/index.php/2019/02/customize-time-date-format-ubuntu-18-04-gnome-panel/
- https://kokufu.blogspot.com/2018/11/gsettings-dconf.html
- https://en.wikipedia.org/wiki/Dconf
- https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/desktop_migration_and_administration_guide/configuration-overview-gsettings-dconf