「Conky/ヒントとテクニック」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
 
325行目: 325行目:
 
次の画像のように表示されます: https://i.imgur.com/pQQbsP6.png
 
次の画像のように表示されます: https://i.imgur.com/pQQbsP6.png
   
  +
== ユーザー提供の設定例 ==
== User-contributed configuration examples ==
 
   
* A sample rings script with nvidia support - [https://gist.github.com/anonymous/85d052c0c23e58bc3666 gist]
+
* nvidia をサポートするサンプル呼び出しスクリプト - [https://gist.github.com/anonymous/85d052c0c23e58bc3666 gist]

2024年4月18日 (木) 22:48時点における最新版

関連記事

パッケージのアップデート情報を表示する

pacman-contrib は、公式リポジトリからのパッケージの更新を表示する checkupdates というスクリプトを提供します。${execi 3600 checkupdates | wc -l} を実行すると、パッケージの総数が表示されます。

テキストファイルの末尾を表示

conky は、conky(1) § tail ファイルをデスクトップにすることができます。これは主にテキストファイルに役立ちます。たとえば、/var/log/ ファイルを読み取り、あらゆる種類のログメッセージを表示します。これらのファイルのほとんどは root によってのみ読み取ることができますが、conkyroot として実行することは推奨されないため、に自分自身を log ユーザーグループ に追加する必要があります。さらに、systemd ログファイルはバイナリファイルであるため、この機能は以前よりも役に立ちません。 ただし、lua スクリプトを使用して実現できます。

天気予報を表示する

これは、外部 Web ページ (通常は天気予報専用のページ) を読み取ることで実現されます。このスレッド を参照してください。lua の別の天気スクリプト: ここ

カウントダウンタイマーを表示する

ConkyTimer は作業の残り時間を表示するシンプルなカウントダウンタイマーです。

conkytimer "<task description>" <min> でタイマーを開始できます。

RSS フィードを表示

外部のスクリプトを実行したり Conky に出力したりすることなく、RSS フィードをネイティブに表示する機能が Conky には備わっています。例えば、Planet Arch の最新の記事のタイトル10件を表示して毎分ごとにフィードを更新したい場合、以下を conky.confTEXT セクションに挿入します:

${rss https://planet.archlinux.org/rss20.xml 300 item_titles 10 }

Arch フォーラムの rss フィードを表示したい場合、次の行を追加します:

${rss https://bbs.archlinux.org/extern.php?action=feed&type=rss 300 item_titles 4}

300 は更新間隔で (15分がデフォルト)、4 は表示するアイテムの数です。

当月のカレンダーを表示します

次の lua スクリプトを使用してカレンダーを表示できます。color1 と設定のデフォルトの色が使用されます。等幅フォントを使用するのが最適です。

 #!/usr/bin/env lua
 
 conky_color = "${color1}%2d${color}"
 
 t = os.date('*t', os.time())
 year, month, currentday = t.year, t.month, t.day
 
 daystart = os.date("*t",os.time{year=year,month=month,day=01}).wday
 
 month_name = os.date("%B")
 
 days_in_month = {
     31, 28, 31, 30, 31, 30, 
     31, 31, 30, 31, 30, 31
 }
 
 -- check for leap year
 -- Any year that is evenly divisible by 4 is a leap year
 -- Any year that is evenly divisible by 100 is a leap year if
 -- it is also evenly divisible by 400.
 LeapYear = function (year)
     return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
 end
 
 if LeapYear(year) then
     days_in_month[2] = 29
 end
 
 title_start = (20 - (string.len(month_name) + 5)) / 2
 
 title = string.rep(" ", math.floor(title_start+0.5)) .. -- add padding to center the title
         (" %s %s\n Su Mo Tu We Th Fr Sa\n"):format(month_name, year)
 
 io.write(title)
 
 function seq(a,b)
     if a > b then
         return
     else
         return a, seq(a+1,b)
     end 
 end
 
 days = days_in_month[month]
 
 io.write(
     string.format(
         string.rep("   ", daystart-1) ..
         string.rep(" %2d", days), seq(1,days)
     ):gsub(string.rep(".",21),"%0\n")
      :gsub(("%2d"):format(currentday),
            (conky_color):format(currentday)
      ) .. "\n"
 )

conky.conf 内に以下を配置し、パスがスクリプトを保存した場所と一致することを確認します。

 conky.text = [[
 ${execpi 3600 ~/.config/conky/cal.lua}
 ]]

rTorrent の統計を表示

このスレッド を参照。

WordPress ブログの統計を表示

python で書かれた ConkyPress という名前の拡張を使うことで表示できます。

新着メールの数を表示する

Conky には IMAP と POP3 のサポートが組み込まれていますが、SSL 経由のアクセスはサポートされていません。Conky の FAQ では、これに stunnel を使用することを推奨しており、設定例が示されています こちら

/etc/stunnel/stunnel.conf を次のように変更し、stunnel.service起動 します:

  1. Service-level configuration for TLS server
[imap]
client = yes
accept  = 143
connect = imap.gmail.com:143
protocol = imap
sslVersion = TLSv1
# Service-level configuration for SSL server
[imaps]
client = yes
accept  = 993
connect = imap.gmail.com:993

Then add the following to conky.conf:

conky.config = {
    imap = "localhost username password [-i 120] [-f 'inbox'] [-p 993]",
}
conky.text {
    Inbox: ${imap_unseen}/${imap_messages}
}

Gmail

2段階認証を使用する場合は、アプリパスワード を使用する必要があります。

方法 1、2、および 3 の場合:

次のファイルのいずれかを便利な場所 (たとえば、~/.scripts/) に作成します。

次に、次の文字列を conky.conf に追加して、Gmail アカウントの新しいメールを 5 分 (300 秒) ごとにチェックして表示します:

${execi 300 python ~/.scripts/gmail.py}

方法 1

このスクリプトは、Gmail の Atom API を介して新規メールの数を取得します。

gmail.py
#!/usr/bin/env python3

import urllib.request

email = 'your email'
password = 'your password'

# Set up authentication for gmail
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='mail.google.com',
                          uri='https://mail.google.com/',
                          user=email,
                          passwd=password)
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)

gmailurl = 'https://mail.google.com/gmail/feed/atom'
with urllib.request.urlopen(gmailurl) as page:
    contents = page.read().decode('utf-8')

ifrom = contents.index('<fullcount>') + 11
ito   = contents.index('</fullcount>')

fullcount = contents[ifrom:ito]

print('{} new emails'.format(fullcount))

方法 2

方法 1 と同じですが、適切な XML 解析が行われます。

gmail.py
#!/usr/bin/env python3

import urllib.request
from xml.etree import ElementTree as etree

email = 'your email'
password = 'your password'

# Set up authentication for gmail
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='mail.google.com',
                          uri='https://mail.google.com/',
                          user=email,
                          passwd=password)
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)

gmailurl = 'https://mail.google.com/gmail/feed/atom'
NS = '{http://purl.org/atom/ns#}'
with urllib.request.urlopen(gmailurl) as source:
    tree = etree.parse(source)
fullcount = tree.find(NS + 'fullcount').text

print('{} new emails'.format(fullcount))

方法 3

同じ方法ですが、curlgrep、および sed を使用します:

gmail.sh
#!/usr/bin/sh

curl -s -u email:password https://mail.google.com/mail/feed/atom | grep fullcount | sed 's/<[^0-9]*>//g'

メールアドレスパスワード を自分のデータに置き換えてください。

IMAP + SSL と Perl を使う

Conky には IMAP アカウントのサポートが組み込まれていますが SSL はサポートしていません。このフォーラムへの投稿 にあるスクリプトを使うことで利用することができます。perl-mail-imapclientperl-io-socket-ssl パッケージの Perl/CPAN Modules Mail::IMAPClient と IO::Socket::SSL が必要です。

Conky に読み込ませる場所に imap.pl という名前のファイルを作成してください。このファイルには、以下の内容を記述します (必要なところは書き換えて下さい):

#!/usr/bin/perl

# gimap.pl by gxmsgx
# description: get the count of unread messages on imap

use strict;
use Mail::IMAPClient;
use IO::Socket::SSL;

my $username = 'example.username'; 
my $password = 'password123'; 

my $socket = IO::Socket::SSL->new(
  PeerAddr => 'imap.server',
  PeerPort => 993
 )
 or die "socket(): $@";

my $client = Mail::IMAPClient->new(
  Socket   => $socket,
  User     => $username,
  Password => $password,
 )
 or die "new(): $@";

if ($client->IsAuthenticated()) {
   my $msgct;

   $client->select("INBOX");
   $msgct = $client->unseen_count||'0';
   print "$msgct\n";
}

$client->logout();

conky.conf に次を追加:

${execpi 300 ~/.conky/imap.pl} 

ファイルの位置は適宜変更してください。

Gmail を使う場合、アプリパスワードを 生成 する必要があります。

もしくは、上に書かれているように stunnel を使うこともできます: #Gmail

IMAP と PHP を使う

PHP を使用する別の方法。PHP をインストールし、/etc/php/php.iniextension=imap のコメントを解除する必要があります。

次に、conky が読み取る場所 (たとえば、~/.scripts/) に imap.php という名前のファイルを作成します。ファイルを 実行可能ファイル にします。

このファイルに、次の内容を追加します (適切な変更を加えてください。)

imap.php
#!/usr/bin/php
<?php
// See http://php.net/manual/function.imap-open.php for more information about
// the mailbox string in the first parameter of imap_open.
// This example is ready to use with Office 365 Exchange Mails,
// just replace your username (=email address) and the password.
$mbox = imap_open("{outlook.office365.com:993/imap/ssl/novalidate-cert}", "username", "password");

// Total number of emails
$nrTotal = imap_num_msg($mbox);
 
// Number of unseen emails. There are other ways using imap_status to count
// unseen messages, but they don't work with Office 365 Exchange. This one does.
$unseen = imap_search($mbox, 'UNSEEN');
$nrUnseen = $unseen ? count($unseen) : 0;
 
// Display the result, format as you like.
echo $nrUnseen.'/'.$nrTotal;
 
// Not needed, because the connection is closed after the script end.
// For the sake of clean public available scripts, we are nice to
// the imap server and close the connection manually.
imap_close($mbox);

conky.conf に追加します:

${execi 300 ~/.scripts/imap.php} 

またはファイルを保存した場所。

上記のスクリプトは A/B と表示します。A は未読メールの数で B はメールボックスに存在するメールの合計数です。imap_Status などの PHP 関数を使うことで他の情報も表示できます (http://php.net/manual/function.imap-status.php) IMAP に関する PHP ドキュメントを見てください: http://php.net/manual/ref.imap.php

有効なネットワークインターフェイスを表示

ネットワークインターフェイスが有効化どうかテストするために、conky の if_existing 変数を使ってインターフェイスの operstate を確認できます。以下はインターフェイスが wlo1 の場合の例です:

draw_graph_borders yes 
${if_existing /sys/class/net/wlo1/operstate up}
${color #0077ff}Net Down:$color ${downspeed wlo1}      ${color #0077ff}Net Up:$color ${upspeed wlo1}
${color #0077ff}${downspeedgraph wlo1 32,155 104E8B 0077ff} $alignr${color #0077ff}${upspeedgraph wlo1 32,155 104E8B 0077ff}
${endif}

次の画像のように表示されます: https://i.imgur.com/pQQbsP6.png

ユーザー提供の設定例

  • nvidia をサポートするサンプル呼び出しスクリプト - gist