0

したがって、私が持っているスクリプトは、i3 で開いているワークスペースが 3 つ未満の場合は画面に大きな dzen2 出力 conky を表示し、開いているワークスペースが 3 つを超える場合は元に戻すことです。スクリプト dzresize.py は次のとおりです。

import subprocess
def main():
    #gets the number of workspaces from i3
    status = subprocess.check_output(["i3-msg", "-t", "get_workspaces"])
    #puts status in a list
    status_list = list(status)
    #sets name to 0
    name = 0
    for i in status_list:
        if i == "name":
            name +=1
    #counts the amount of name in status_list
    if len(status_list) <=3:
    #if the workspaces are less than or equal to 3, expands dzen2 with conky output
            subprocess.check_output(["conky", "-d", "-c", "~/bin/conkyrc_cli|dzen2", "-fg", "#666666", "-bg", "#333333", "-ta", "left", "-w", "725", "-x", "54", "-y", "750"])
    else:
    #if the workspaces are greater than or equal to 3 run the minimal smaller size dzen2 with conky
            subprocess.check_output(["dzconky.sh"])
main()

スクリプトの出力は次のとおりです。

Conky: forked to background, pid is 18519

i3-msg -t get_workspaces のサンプル出力 (2 つのワークスペースを開いている場合):

i3-msg -t get_workspaces
[{"num":1,"name":"1","visible":false,"focused":false,"rect":{"x":0,"y":0,"width":1366,"height":749},"#output":"LVDS1","urgent":false},{"num":2,"name":"2","visible":true,"focused":true,"rect":{"x":0,"y":#0,"width":1366,"height":749},"output":"LVDS1","urgent":false}]

i3、dzen2、およびファイル ~/bin/conkyrc_cli および ~/bin/dzconky.sh に依存しています。~/bin/conkyrc_cli:

# Conky configuration for Dzen2, to be piped into i3bar
##############################################
#  Settings
##############################################
background no
out_to_console yes
update_interval 1.0
total_run_times 0
use_spacer none
TEXT
^fg(\#6699cc)Processor^fg()^fg(green)${cpu cpu0}.00%^fg()^fg(white)|^fg(\#6699cc)Memory^fg()^fg(green)${memperc}.00%^fg()^fg(white)|^fg(\#6699cc)Root^fg()^fg(green)${fs_used_perc /}.00%^fg()^fg(white)|^fg(\#6699cc)Home^fg()^fg(green)${fs_used_perc /home}.00%^fg()^fg(white)|^fg(\#6699cc)Temperature^fg()^fg(green)${hwmon temp 1}'C^fg()^fg(white)|^fg(\#6699cc)Dn^fg()^fg(green)${downspeedf wlan0}KiB^fg()^fg(white)|^fg(\#6699cc)U^fg()^fg(green)${upspeedf wlan0}KiB^fg()

~/bin/dzconky.sh:

#!/bin/sh
exec conky -d -c "$HOME/bin/conkyrc_cli" | dzen2 -fg "#666666" -bg "#333333" -ta left -w 607 -x 188 -y 750 &
exit 0

編集:新しい変更と新しい出力を反映するようにコードに更新

4

2 に答える 2

2

あなたはすっかり忘れ,ていたsubprocess.call([...])

["i3-msg", "-t", "get_workspaces"]

編集:

if len(status_list) <=3:
    subprocess.check_output(["dzconky_for_3_workspaces.sh"])
else:
    subprocess.check_output(["dzconky.sh"])

dzconky_for_3_workspaces.sh

#!/bin/sh
exec conky -d -c "$HOME/bin/conkyrc_cli" | dzen2 -fg "#666666" -bg "#333333" -ta left -w 725 -x 54 -y 750 &
exit 0
于 2013-07-07T22:58:28.500 に答える
0

Python のshパッケージを使用できます。シェル実行用の非常に優れた pythonic ラッパーです。ドキュメントを見ると、shおそらく必要なほとんどのケースを数行で実行できることがわかります。

インストール

pip インストール sh

ドキュメントから:

次のように簡単:

sh import curl、git、ifconfig、ls から
ls()
git('フェッチ')
ifconfig(a=真)

リダイレクト:

ls(_out="files.list")
ls("存在しない", _err="error.txt")
# stdin には _in もあります

配管:

# このディレクトリを最大のファイルでソート
print(sort(du(glob("*"), "-sb"), "-rn"))
于 2013-07-07T23:18:41.153 に答える