
내 컴퓨터는 5분 동안 활동이 없으면 일시 중지되지만 4분 30초 동안 활동이 없으면 명령을 실행하고 싶습니다. 4분 30초 후에 명령을 실행할 수 있는 방법이 있습니까?아니요전체 화면 창이 있고 키보드 및 마우스 활동이 없습니까?
저는 GNOME 3.18과 함께 Ubuntu GNOME 15.10을 실행하고 있습니다. 나는 이미 살펴보았다이 질문. 그러나 xprintidle
전체 화면 창에서는 실행되지 않고 키보드 및 마우스 활동에 의해서만 실행됩니다.
답변1
유휴 시간 이후 명령 실행(전체 화면 모두에 의해 트리거됨)그리고마우스/키보드 활동
Paranoid Panda님, 안녕하세요. 아래 스크립트는 설명대로 작동해야 합니다.
문제는 (모든) 창 전체 화면과 마우스 또는 키보드 활동이 모두 "실제" 유휴 시간을 재설정해야 한다는 것이었습니다. 명령줄에서 재설정할 수 없기 때문에 xprintidle
전체 화면 창에서 유휴 시간을 빼서 문제를 해결했습니다.
- 루프에서 스크립트는 현재 유휴 시간을 조회합니다.
xrandr
창이 최대화되어 있는 경우( 및 를 모두 사용하여 창이 화면 해상도만큼 큰지 확인wmctrl -lG
),현재의유휴 시간에서 유휴 시간을 빼면 창이 더 이상 전체 화면이 아닌 경우에도 올바른 "실제" 유휴 시간이 됩니다.
스크립트
#!/usr/bin/env python3
import subprocess
import time
import sys
idletime = int(sys.argv[1])
command = sys.argv[2]
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8").strip()
def get_res():
xr = [s for s in get(["xrandr"]).split() \
if "+0+0" in s][0].split("x"); xr[1] = xr[1].split("+")[0]
return xr
res = get_res()
def check():
front = [l for l in get(["xprop", "-root"]).splitlines() \
if "_NET_ACTIVE_WINDOW(WINDOW):" in l][0].split("#")[-1].strip()
front = front[:2]+(10-len(front))*"0"+front[2:]
try:
wdata = subprocess.check_output(
["wmctrl", "-lG"]
).decode("utf-8").splitlines()
match = [l for l in wdata if front in l][0].split()[4:6]
if match == res:
return True
else:
return False
except subprocess.CalledProcessError:
pass
minus = 0; real_idle = 0; t1 = 0; due_1 = False
while True:
time.sleep(1)
fscreen = check()
t2 = int(int(get(["xprintidle"]))/1000)
if t2 < t1:
minus = 0; real_idle = 0
else:
if fscreen == True:
minus = t2
real_idle = t2 - minus
due_2 = [real_idle > idletime][0]
if all([real_idle > idletime, due_1 != due_2]):
subprocess.Popen(["/bin/bash", "-c", command])
due_1 = due_2
t1 = t2
사용
스크립트에는 다음이 필요
wmctrl
합니다xprintidle
.sudo apt-get install xdotool xprintidle
스크립트를 빈 파일에 복사하고 다른 이름으로 저장하세요.
run_ontime.py
다음 명령으로 실행하세요.
python3 /path/to/run_ontime.py <seconds> <command>
명령에 공백이 포함된 경우 명령을 따옴표로 묶어야 합니다. 예를 들어 다음과 같이 테스트했습니다.
python3 /path/to/run_ontime.py 10 "firefox askubuntu.com"
그것은 일을했다 :)
메모
유휴 시간이 지날 때마다 명령이 한 번씩 실행됩니다.