Ubuntu Unity 16.04에서 대기 뚜껑을 빠르게 비활성화하려면 어떻게해야합니까? 전환하지 않고 뚜껑을 닫고

덮개를 닫을 때 대기 기능을 빠르게 비활성화하는 가장 빠른 방법은 무엇입니까? 이 동작을 매우 좋아하지만 특히 음악을 재생할 때 기기를 대기 모드로 전환하지 않고 뚜껑을 닫고 싶습니다.

그러나이 기능을 영구적으로 비활성화하고 싶지는 않지만 예를 들어 음악 듣기가 끝날 때까지 일시적으로 끕니다.

어쩌면 Caffeine 와 유사한 표시기가 있습니까?



답변

아래의 스크립트 는 “nothing”과 “suspend”사이에서 닫힌 동작을 토글 합니다.

#!/usr/bin/env python3
import subprocess

key = ["org.gnome.settings-daemon.plugins.power",
       "lid-close-ac-action", "lid-close-battery-action"]

currstate = subprocess.check_output(["gsettings", "get",
    key[0], key[1]]).decode("utf-8").strip()

if currstate == "'suspend'":
    command = "'nothing'"
    subprocess.Popen(["notify-send", "Lid closes with no action"])
else:
    command = "'suspend'"
    subprocess.Popen(["notify-send", "Suspend will be activated when lid closes"])

for k in [key[1], key[2]]:
    subprocess.Popen(["gsettings", "set", key[0], k, command])

… 현재 설정된 상태를 알려주십시오.

사용하는 방법

간단히:

  • 스크립트를 빈 파일로 복사하여 다른 이름으로 저장하십시오. toggle_lid.py
  • 바로 가기 키에 추가하십시오 : 시스템 설정> “키보드”> “바로 가기”> “사용자 정의 바로 가기”를 선택하십시오. “+”를 클릭하고 다음 명령을 추가하십시오.

    python3 /path/to/toggle_lid.py
    

설명

닫힘 동작 설정의 현재 상태는 명령으로 검색 할 수 있습니다.

gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action

(전원) 및

gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action

(배터리에)

스크립트는 현재 상태를 읽고 다음 명령으로 반대 ( ‘suspend’/ ‘nothing’)를 설정합니다.

gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action '<action>'

선택적으로 (추가로)

선택적으로 / 추가로, 표시기를 검출기로 실행하여 뚜껑 설정의 현재 상태를 표시 할 수 있습니다. 다음과 같이 표시됩니다.

… 패널에서 뚜껑을 닫을 때 일시 중단이 방지되면 그렇지 않은 경우 회색으로 표시됩니다.

스크립트

#!/usr/bin/env python3
import subprocess
import os
import time
import signal
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, AppIndicator3, GObject
from threading import Thread

key = ["org.gnome.settings-daemon.plugins.power",
       "lid-close-ac-action", "lid-close-battery-action"]

currpath = os.path.dirname(os.path.realpath(__file__))

def runs():
    # The test True/False
    return subprocess.check_output([
        "gsettings", "get", key[0], key[1]
        ]).decode("utf-8").strip() == "'suspend'"

class Indicator():
    def __init__(self):
        self.app = 'show_proc'
        iconpath = currpath+"/nocolor.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.update = Thread(target=self.check_runs)
        # daemonize the thread to make the indicator stopable
        self.update.setDaemon(True)
        self.update.start()

    def check_runs(self):
        # the function (thread), checking for the process to run
        runs1 = None
        while True:
            time.sleep(1)
            runs2 = runs()
            # if there is a change in state, update the icon
            if runs1 != runs2:
                if runs2:
                    # set the icon to show
                    GObject.idle_add(
                        self.indicator.set_icon,
                        currpath+"/nocolor.png",
                        priority=GObject.PRIORITY_DEFAULT
                        )
                else:
                    # set the icon to hide
                    GObject.idle_add(
                        self.indicator.set_icon,
                        currpath+"/green.png",
                        priority=GObject.PRIORITY_DEFAULT
                        )
            runs1 = runs2

    def create_menu(self):
        menu = Gtk.Menu()
        # quit
        item_quit = Gtk.MenuItem('Quit')
        item_quit.connect('activate', self.stop)
        menu.append(item_quit)
        menu.show_all()
        return menu

    def stop(self, source):
        Gtk.main_quit()

Indicator()
GObject.threads_init()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()

사용하는 방법

  1. 위의 스크립트를 빈 파일로 복사하여 다른 이름으로 저장하십시오. show_state.py
  2. 아래의 두 아이콘을 모두 복사하고 (오른쪽 클릭-> 다른 이름으로 저장) 아이콘 을 하나의 동일한 디렉토리에 저장하고 아래 표시된대로 정확하게 이름을 지정하십시오.show_proc.py

    green.png

    nocolor.png

  3. 이제 show_state.py다음 명령으로 테스트 실행 하십시오.

    python3 /path/to/show_state.py
    

    이 답변의 첫 번째 섹션을 설정 한 바로 가기를 눌러 현재 상태를 변경하십시오.

  4. 모두 제대로 작동하면 시작 응용 프로그램에 다음을 추가하십시오.

    /bin/bash -c "sleep 15 && python3 /path/to/show_state.py"
    

노트

위의 탐지기 표시기는 이 답변 의 편집 된 버전입니다 . 단순히 기능의 테스트를 변경하여 runs()(선택적 따라 패널 아이콘), 당신의 상태를 표시하는 데 사용할 수 있습니다 아무것도 있습니다 True또는 False.


답변

또 다른 옵션은 Ubuntu Settings-Power에서 “Suspend”에서 “Nothing”으로 변경하는 것입니다.

추신 : 이것은 알림 영역에 표시기를 제공하지 않지만 새로운 사용자를위한 스크립트를 만드는 것보다 간단합니다.

PPS :이 화면의 스냅 샷에서 UPS는 배터리가있는 랩탑이 아닌 케이블 모뎀 + Sony Android TV 용입니다. HAHA.