스크립팅을 처음 접했습니다. 다음은 내가 작성한 간단한 스크립트 (작동)이며 5 분이 지나면 이미지를 표시합니다.
sleep 300 && firefox file:///home/tasks/fiveminutes.jpg
내 질문은 다음과 같습니다. 때로는 타이머를 시작했는지 기억할 수 없습니다. 타이머를 시작하는 순간부터 종료하는 순간까지 5 분 동안 나타나는 텍스트 또는 아이콘 표시를 추가하는 방법이 있습니까 (이상적으로 작업 표시 줄에 있지만 어디에서나 좋을 것입니다)?
어떤 제안이라도 대단히 감사합니다.
답변
프로세스가 시작될 때 팝업 알림을 표시 할 수 있습니다. 스크립트를 다음과 같이 변경하십시오.
notify-send "Your image will arrive" "after 5 minutes" && sleep 300 && firefox file:///home/tasks/fiveminutes.jpg
명령을 사용하여 -t
매개 변수 (및 밀리 초 단위)로 알림 풍선의 지속 시간을 설정할 수 있습니다 ( notify-send
예 : 5 분 동안 지속 시간 설정).
notify-send -t 300000 "heading" "text"
그러나 이 매개 변수가 데스크탑 환경에 따라 완전히 무시 될 수있다 (참조 이 ).
답변
다음과 같은 스크립트를 갖는 것으로 충분합니다.
#!/usr/bin/env bash
while true
do
if pgrep -f gedit > /dev/null
then
printf "\r%b" "\033[2K"
printf "Script is running"
else
printf "\r%b" "\033[2K"
printf "Script is not running."
fi
sleep 0.25
done
이것은 매우 일반적인 방법이며 셸 스크립트에서 자주 사용됩니다. 이것이하는 일은 지속적으로 실행되며 매 분기마다 스크립트가를 통해 실행되고 있는지 확인합니다 pgrep -f
. if..fi
쉘 스크립트의 명령문은 명령의 종료 상태에서 작동하므로 pgrep -f
성공적인 종료 상태를 리턴하면 스크립트 프로세스를 찾았으며 실행 중임을 의미합니다. 그렇지 않으면 else 문으로 이동합니다.
두 경우 모두 실행 중인지 여부를 알려주는 텍스트 줄을 인쇄합니다. printf "\r%b" "\033[2K"
라인을 지우는 이스케이프 시퀀스를 인쇄하기 위해 추가되었습니다 (청소기 출력 전용).
거기에서 하늘이 한계입니다. 파이프를 통해 해당 텍스트를 터미널의 다른 프로세스로 전달하거나 모니터링 스크립트의 출력을 indicator-sysmonitor 로 전달하여 표시기에 사용자 정의 정보를 표시 할 수 있습니다. 통해 설치할 수 있습니다
sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor
sudo apt-get update
sudo apt-get install indicator-sysmonitor
그런 다음 모니터링 스크립트가 될 사용자 정의 명령을 표시하도록 표시기를 구성하십시오. 사용자 정의 명령 구성의 예는 여기 에서 찾을 수 있습니다 .
물론 파이썬으로 자신의 인디케이터를 작성할 수는 있지만 이미 툴을 가지고있을 때 과잉 일 수 있습니다.
답변
이 답변 과 인터넷에 대한 추가 연구를 기반으로 한 Python Launcher 는 Ubuntu 16.04에서 잘 작동합니다.
#!/usr/bin/env python3
import signal
import gi
import os
import subprocess
import sys
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, AppIndicator3, GObject
import time
from threading import Thread
# Execute the script
script = os.path.basename(sys.argv[1])
subprocess.Popen(sys.argv[1:])
script_name = script.rsplit('/', 1)[-1]
class Indicator():
def __init__(self):
self.app = 'Script indicator'
iconpath = "/usr/share/unity/icons/launcher_bfb.png"
self.indicator = AppIndicator3.Indicator.new(
self.app, iconpath,
AppIndicator3.IndicatorCategory.OTHER)
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.create_menu())
self.indicator.set_label("Script Indicator", self.app)
# the thread:
self.update = Thread(target=self.show_seconds)
# daemonize the thread to make the indicator stopable
self.update.setDaemon(True)
self.update.start()
def create_menu(self):
menu = Gtk.Menu()
# menu item 1
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', self.stop)
menu.append(item_quit)
menu.show_all()
return menu
def show_seconds(self):
global script_name
t = 0
process = subprocess.call(['pgrep', script_name], stdout=subprocess.PIPE)
while (process == 0):
t += 1
GObject.idle_add(
self.indicator.set_label,
script_name + ' ' + str(t) + 's', self.app,
priority=GObject.PRIORITY_DEFAULT
)
time.sleep(1)
process = subprocess.call(['pgrep', script_name], stdout=subprocess.PIPE)
subprocess.call(['notify-send', script_name + ' ended in ' + str(t) + 's'])
time.sleep(10)
Gtk.main_quit()
def stop(self, source):
global script_name
subprocess.call(['pkill', script_name], stdout=subprocess.PIPE)
Gtk.main_quit()
Indicator()
# this is where we call GObject.threads_init()
GObject.threads_init()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
- 스크립트를 개선 할 수있는 방법이 있다면 주저하지 말고 답을 편집하십시오. 나는 파이썬에 대한 경험이별로 없습니다.
실행 파일을 작성하고 위의 행을 내용으로 배치하십시오. 파일이라고 가정 해 봅시다 script-indicator.py
. 필요와 스크립트 특성 에 따라 다음 방법 중 하나를 사용하여이 실행기 를 사용할 수 있습니다 .
./script-indicator.py /path/to/script.sh
./script-indicator.py /path/to/script.sh &
./script-indicator.py /path/to/script.sh > out.log &
./script-indicator.py /path/to/script.sh > /dev/null &
script.sh
표시하려는 곳 은 어디 입니까?
종료시 스크린 샷 script.sh
:
- 애니메이션 데모를 보려면 이미지를 클릭하십시오.
또는 /usr/local/bin
쉘 명령 시스템 전체에서 액세스 할 수 있도록 스크립트를 배치 할 수 있습니다 . 이 전용 GitHub Gist 에서 다운로드 할 수 있습니다 .
sudo wget -qO /usr/local/bin/script-indicator https://gist.githubusercontent.com/pa4080/4e498881035e2b5062278b8c52252dc1/raw/c828e1becc8fdf49bf9237c32b6524b016948fe8/script-indicator.py
sudo chmod +x /usr/local/bin/script-indicator
다음 구문으로 테스트했습니다.
script-indicator /path/to/script.sh
script-indicator /path/to/script.sh &
script-indicator /path/to/script.sh > output.log
script-indicator /path/to/script.sh > output.log &
script-indicator /path/to/script.sh > /dev/null
script-indicator /path/to/script.sh > /dev/null &
nohup script-indicator /path/to/script.sh >/dev/null 2>&1 &
# etc...
답변
와 osd_cat
다음 과 같은 패키지 osd_cat
에서 사용할 수 있습니다 xosd-bin
.
<<<"runs" osd_cat -d5 -i20 -o50 -f"-*-*-*-*-*-*-100-*-*-*-*-*-*-*" && firefox
글꼴 크기와이에 “실행” 100
에 대한 5
위치에서 초 20,50
화면과 시작에 firefox
그것을 준비 – 당신이 필요하지 않은 sleep
이 방법으로. 당신이 사용할 수 xfontsel
있는 X 논리적 글꼴 설명자 (이상한 얻을 -*-*-…
에 대한 꼬추) -f
다른 글꼴을 사용하려면 옵션, 예를. man osd_cat
더 많은 옵션을 읽으십시오 .
와 yad
yad
다음과 같이 사용할 수 있습니다 .
yad --title=runs --text="it’s running!" --timeout=5 --button=Fire:1 --button=Abort:0 || firefox
이 예제에서는 명령을 중단하거나 즉시 실행할 수 있다는 장점이 있습니다 5
.
답변
이 이미 작동하는 스크립트를multi-timer
가져 와서 일반적인 카운트 다운 타이머를 위해 대부분을 제거 할 수 있습니다 .
indicator-sysmonitor
Serge의 답변에서 설명한 것과 동일 합니다.
Systray 부분 Brightness: 2344
도 동일한 스크립트로 표시됩니다.
bash 코드의 불필요한 부분을 제거하는 것이 새로운 사용자에게는 너무 어려운 show-sleep
경우 필요한 제한된 기능을 갖춘 여기에 스크립트를 게시하게되어 기쁩니다 . 아래에 의견을 게시하십시오.