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

提供: ArchWiki
ナビゲーションに移動 検索に移動
(英語版から転載)
 
 
(同じ利用者による、間の12版が非表示)
5行目: 5行目:
 
{{Related articles end}}
 
{{Related articles end}}
   
  +
== パッケージのアップデート情報を表示する ==
== Display package update information ==
 
   
{{Pkg|pacman-contrib}} provides a script called {{ic|checkupdates}} which displays package updates from the official repos. Use {{ic|<nowiki>${execi 3600 checkupdates | wc -l}</nowiki>}} to display the total number of packages.
+
{{Pkg|pacman-contrib}} は、公式リポジトリからのパッケージの更新を表示する {{ic|checkupdates}} というスクリプトを提供します。{{ic|<nowiki>${execi 3600 checkupdates | wc -l}</nowiki>}} を実行すると、パッケージの総数が表示されます。
   
  +
== テキストファイルの末尾を表示 ==
== tail text files ==
 
   
  +
''conky'' は、{{man|1|conky|tail}} ファイルをデスクトップにすることができます。これは主にテキストファイルに役立ちます。たとえば、{{ic|/var/log/}} ファイルを読み取り、あらゆる種類のログメッセージを表示します。これらのファイルのほとんどは {{ic|root}} によってのみ読み取ることができますが、''conky'' を {{ic|root}} として実行することは推奨されないため、に自分自身を {{ic|log}} [[ユーザーグループ]] に追加する必要があります。さらに、[[systemd]] ログファイルはバイナリファイルであるため、この機能は以前よりも役に立ちません。 ただし、[[lua]] スクリプトを使用して実現できます。
''conky'' is able to {{man|1|conky|tail}} files to your desktop, which is mostly useful for text files. Such as reading {{ic|/var/log/}} files to display all kinds of log messages. Most of these files can only be read by {{ic|root}}, but running ''conky'' as {{ic|root}} is not recommended, so you will need to add yourself to the {{ic|log}} [[user group]]. In addition, since [[systemd]] log files are binary files, this feature is less useful then it used to be. However, it could be accomplished using [[lua]] scripts.
 
   
  +
== 天気予報を表示する ==
== Display weather forecast ==
 
   
It is achieved by reading external web pages, usually pages dedicated to weather forecast. See [https://bbs.archlinux.org/viewtopic.php?id=37381 this thread]. Another weather script in lua: [https://bbs.archlinux.org/viewtopic.php?id=222998 here]
+
これは、外部 Web ページ (通常は天気予報専用のページ) を読み取ることで実現されます。[https://bbs.archlinux.org/viewtopic.php?id=37381 このスレッド] を参照してください。lua の別の天気スクリプト: [https://bbs.archlinux.org/viewtopic.php?id=222998 ここ]
   
  +
== カウントダウンタイマーを表示する ==
== Display a countdown timer ==
 
   
[https://github.com/orschiro/scriptlets/tree/master/ConkyTimer ConkyTimer] is a simple countdown timer that displays the remaining time of a defined task.
+
[https://github.com/orschiro/scriptlets/tree/master/ConkyTimer ConkyTimer] は作業の残り時間を表示するシンプルなカウントダウンタイマーです。
   
Start the timer using {{ic|conkytimer "<task description>" <min>}}.
+
{{ic|conkytimer "<task description>" <min>}} でタイマーを開始できます。
   
== Display RSS feeds ==
+
== RSS フィードを表示 ==
   
  +
外部のスクリプトを実行したり Conky に出力したりすることなく、RSS フィードをネイティブに表示する機能が Conky には備わっています。例えば、Planet Arch の最新の記事のタイトル10件を表示して毎分ごとにフィードを更新したい場合、以下を {{ic|conky.conf}} の {{ic|TEXT}} セクションに挿入します:
''Conky'' has the ability to display RSS feeds natively without the need for an outside script to run and output into Conky. For example, to display the titles of the ten most recent Planet Arch updates and refresh the feed every minute, you would put this into your {{ic|conky.conf}} in the {{ic|TEXT}} section:
 
   
 
${rss https://planet.archlinux.org/rss20.xml 300 item_titles 10 }
 
${rss https://planet.archlinux.org/rss20.xml 300 item_titles 10 }
  +
Arch フォーラムの rss フィードを表示したい場合、次の行を追加します:
If you want to display Arch Forum rss feed, add this line:
 
 
${rss https://bbs.archlinux.org/extern.php?action=feed&type=rss 300 item_titles 4}
 
${rss https://bbs.archlinux.org/extern.php?action=feed&type=rss 300 item_titles 4}
  +
300 は更新間隔で (15分がデフォルト)、4 は表示するアイテムの数です。
where 300 is in seconds the refresh interval (15 minutes is default), 4 the number of items you wish to show.
 
   
  +
== 当月のカレンダーを表示します ==
== Display a calendar for the current month ==
 
   
  +
次の lua スクリプトを使用してカレンダーを表示できます。{{ic|color1}} と設定のデフォルトの色が使用されます。等幅フォントを使用するのが最適です。
You can use the following lua script to display a calendar. It uses {{ic|color1}} and the default color from your configuration. It looks best with a monospace font.
 
   
 
#!/usr/bin/env lua
 
#!/usr/bin/env lua
91行目: 91行目:
 
)
 
)
   
  +
{{ic|conky.conf}} 内に以下を配置し、パスがスクリプトを保存した場所と一致することを確認します。
Inside your {{ic|conky.conf}} you can then place the following, making sure the path matches where you saved the script.
 
   
 
conky.text = [[
 
conky.text = [[
97行目: 97行目:
 
]]
 
]]
   
== Display rTorrent stats ==
+
== rTorrent の統計を表示 ==
   
See [https://bbs.archlinux.org/viewtopic.php?id=67304 this thread].
+
[https://bbs.archlinux.org/viewtopic.php?id=67304 このスレッド] を参照。
   
== Display your WordPress blog stats ==
+
== WordPress ブログの統計を表示 ==
   
This can be achieved by using the in python written extension named [https://evilshit.wordpress.com/2013/04/20/conkypress-a-wordpress-stats-visualization-tool-for-your-desktop/ ConkyPress].
+
python で書かれた [http://evilshit.wordpress.com/2013/04/20/conkypress-a-wordpress-stats-visualization-tool-for-your-desktop/ ConkyPress] という名前の拡張を使うことで表示できます。
   
  +
== 新着メールの数を表示する ==
== Display number of new emails ==
 
   
Conky has built in support for IMAP and POP3, but does not have support for access over ssl. Conky's FAQ recommends using {{Pkg|stunnel}} for this and has an example configuration [https://conky.sourceforge.net/faq.html#Conky's-built-in-IMAP-and-POP3-doesn't-support-SSL-or-TLS/ here].
+
Conky には IMAP POP3 のサポートが組み込まれていますが、SSL 経由のアクセスはサポートされていません。Conky FAQ では、これに {{Pkg|stunnel}} を使用することを推奨しており、設定例が示されています [https://conky.sourceforge.net/faq.html#Conky's-built-in-IMAP-and-POP3-doesn't-support-SSL-or-TLS/ こちら]
   
Modify {{ic|/etc/stunnel/stunnel.conf}} as follows, and then [[start]] {{ic|stunnel.service}}:
+
{{ic|/etc/stunnel/stunnel.conf}} を次のように変更し、{{ic|stunnel.service}} を [[起動]] します:
 
 
 
# Service-level configuration for TLS server
 
# Service-level configuration for TLS server
136行目: 136行目:
 
=== Gmail ===
 
=== Gmail ===
   
If you use 2-factor authentication, you need to use an [https://myaccount.google.com/apppasswords App Password].
+
2段階認証を使用する場合は、[https://myaccount.google.com/apppasswords アプリパスワード] を使用する必要があります。
   
  +
方法 1、2、および 3 の場合:
For method 1, 2 and 3:
 
   
  +
次のファイルのいずれかを便利な場所 (たとえば、{{ic|~/.scripts/}}) に作成します。
Create one of the following files in a convenient location (for example in {{ic|~/.scripts/}}).
 
   
  +
次に、次の文字列を {{ic|conky.conf}} に追加して、Gmail アカウントの新しいメールを 5 分 (300 秒) ごとにチェックして表示します:
Then add the following string to your {{ic|conky.conf}} in order the check your Gmail account for new email every five minutes (300 seconds) and display:
 
 
${execi 300 python ~/.scripts/gmail.py}
 
${execi 300 python ~/.scripts/gmail.py}
   
==== method 1 ====
+
==== 方法 1 ====
   
  +
このスクリプトは、Gmail の Atom API を介して新規メールの数を取得します。
This script uses retrieves the number of new email via Gmail's Atom API.
 
 
{{hc|gmail.py|<nowiki>
 
{{hc|gmail.py|<nowiki>
 
#!/usr/bin/env python3
 
#!/usr/bin/env python3
179行目: 179行目:
 
</nowiki>}}
 
</nowiki>}}
   
==== method 2 ====
+
==== 方法 2 ====
   
  +
方法 1 と同じですが、適切な XML 解析が行われます。
Same as method 1, but does proper XML parsing.
 
   
 
{{hc|gmail.py|<nowiki>
 
{{hc|gmail.py|<nowiki>
211行目: 211行目:
 
</nowiki>}}
 
</nowiki>}}
   
==== method 3 ====
+
==== 方法 3 ====
   
The same way, but with using {{ic|curl}}, {{ic|grep}} and {{ic|sed}}:
+
同じ方法ですが、{{ic|curl}}{{ic|grep}}、および {{ic|sed}} を使用します:
 
 
 
{{hc|gmail.sh|
 
{{hc|gmail.sh|
221行目: 221行目:
 
}}
 
}}
   
  +
''メールアドレス'' と ''パスワード'' を自分のデータに置き換えてください。
replace ''email'' and ''password'' with your data.
 
   
==== IMAP + SSL using Perl ====
+
==== IMAP + SSL Perl を使う ====
  +
''Conky'' には IMAP アカウントのサポートが組み込まれていますが SSL はサポートしていません。[http://www.unix.com/shell-programming-scripting/115322-perl-conky-gmail-imap-unread-message-count.html このフォーラムへの投稿] にあるスクリプトを使うことで利用することができます。{{Pkg|perl-mail-imapclient}} と {{Pkg|perl-io-socket-ssl}} パッケージの Perl/CPAN Modules Mail::IMAPClient と IO::Socket::SSL が必要です。
   
  +
Conky に読み込ませる場所に {{ic|imap.pl}} という名前のファイルを作成してください。このファイルには、以下の内容を記述します (必要なところは書き換えて下さい):
''Conky'' has built in support for IMAP accounts but does not support SSL. This can be provided using this script from [https://www.unix.com/shell-programming-scripting/115322-perl-conky-gmail-imap-unread-message-count.html this forum post]. This requires the Perl/CPAN Modules Mail::IMAPClient and IO::Socket::SSL which are in the {{Pkg|perl-mail-imapclient}} and {{Pkg|perl-io-socket-ssl}} packages
 
  +
#!/usr/bin/perl
 
Create a file named {{ic|imap.pl}} in a location to be read by ''conky'' (for example in {{ic|~/.scripts/}}). In this file, add (with the appropriate changes):
 
{{hc|imap.pl|<nowiki>
 
#!/usr/bin/perl
 
 
 
# by gxmsgx
+
# gimap.pl by gxmsgx
# description: get the count of unread messages on imap
+
# 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(): $@";
 
 
 
  +
use strict;
my $client = Mail::IMAPClient->new(
 
  +
use Mail::IMAPClient;
Socket => $socket,
 
  +
use IO::Socket::SSL;
User => $username,
 
  +
Password => $password,
 
  +
my $username = 'example.username';
)
 
  +
my $password = 'password123';
or die "new(): $@";
 
  +
  +
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";
  +
}
 
 
if ($client->IsAuthenticated()) {
+
$client->logout();
my $msgct;
 
   
  +
{{ic|conky.conf}} に次を追加:
$client->select("INBOX");
 
  +
${execpi 300 ~/.conky/imap.pl}
$msgct = $client->unseen_count||'0';
 
  +
ファイルの位置は適宜変更してください。
print "$msgct\n";
 
}
 
   
  +
Gmail を使う場合、アプリパスワードを [https://www.google.com/accounts/IssuedAuthSubTokens?hide_authsub=1 生成] する必要があります。
$client->logout();
 
</nowiki>}}
 
   
  +
もしくは、上に書かれているように stunnel を使うこともできます: [[#Gmail]]
Add to {{ic|conky.conf}}:
 
${execi 300 ~/.scripts/imap.pl}
 
or wherever you saved the file.
 
   
  +
==== IMAP と PHP を使う ====
If you use Gmail you might need to [https://www.google.com/accounts/IssuedAuthSubTokens?hide_authsub=1 generate] an application specific password.
 
   
  +
PHP を使用する別の方法。PHP をインストールし、{{ic|/etc/php/php.ini}} で {{ic|1=extension=imap}} のコメントを解除する必要があります。
Alternatively, you can use stunnel as shown above: [[#Gmail]]
 
   
  +
次に、''conky'' が読み取る場所 (たとえば、{{ic|~/.scripts/}}) に {{ic|imap.php}} という名前のファイルを作成します。ファイルを [[ヘルプ:読み方#実行可能属性の付与|実行可能ファイル]] にします。
==== IMAP using PHP ====
 
   
  +
このファイルに、次の内容を追加します (適切な変更を加えてください。)
Another alternative using PHP. PHP needs to be installed and {{ic|1=extension=imap}} must be uncommented in {{ic|/etc/php/php.ini}}.
 
 
Then create a file named {{ic|imap.php}} in a location to be read by ''conky'' (for example in {{ic|~/.scripts/}}). Make the file [[executable]].
 
 
In this file, add (with the appropriate changes):
 
   
 
{{hc|imap.php|<nowiki>
 
{{hc|imap.php|<nowiki>
307行目: 304行目:
 
</nowiki>}}
 
</nowiki>}}
   
Add to {{ic|conky.conf}}:
+
{{ic|conky.conf}} に追加します:
   
 
${execi 300 ~/.scripts/imap.php}
 
${execi 300 ~/.scripts/imap.php}
   
  +
またはファイルを保存した場所。
or wherever you saved the file.
 
   
This script displays A/B where A is the number of unseen emails and B is the total number of mails in the mailbox. There are a lot of other information available through a lot of PHP functions like with imap_Status (https://php.net/manual/function.imap-status.php). Just see the PHP docs about IMAP: https://php.net/manual/ref.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
   
  +
== 有効なネットワークインターフェイスを表示 ==
== Show graphic of active network interface ==
 
   
  +
ネットワークインターフェイスが有効化どうかテストするために、conky の {{ic|if_existing}} 変数を使ってインターフェイスの {{ic|operstate}} を確認できます。以下はインターフェイスが {{ic|wlo1}} の場合の例です:
To test if a network inferface is currently active, you can use the test conky variable {{ic | if_existing}} on the {{ic | operstate}} of the interface. Here is an example for wlo1 :
 
   
 
{{bc |draw_graph_borders yes
 
{{bc |draw_graph_borders yes
326行目: 323行目:
 
}}
 
}}
   
  +
次の画像のように表示されます: https://i.imgur.com/pQQbsP6.png
This is the expected result :
 
 
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