鎖定單一應用程式的介面

鎖定單一應用程式的介面

我可以鎖定特定應用程式的介面而不鎖定整個螢幕嗎?由於同事經常訪問我的桌面以添加更改,因此在離開辦公桌時能夠使某些應用程式保持開啟狀態在工作中非常有用。然而,我想鎖定 pidgin/skype/firefox/thunderbird,以便它保持登入狀態,但如果沒有單獨的密碼則無法使用/無法查看。

答案1

隱藏應用程式窗口,密碼使其再次可見

編輯後的版本這個腳本將(完全)隱藏/顯示介面(視窗)任何應用程序,在腳本的頭部部分列出(切換)。

它具有“溫和”密碼保護,因為密碼儲存在腳本內。運行腳本的組合鍵將是另一個阻礙存取的障礙。對於您提到的情況,這可能就足夠了,但您必須做出決定。

在此輸入影像描述

如何使用

  1. 該腳本同時使用xdotoolwmctrl

    sudo apt-get install xdotool wmctrl
    
  2. 然後只需將下面的腳本複製到一個空文件中,另存為password_app.py,如果您想要當前密碼“Monkey”,請更改該行:

    if passw == "Monkey":
    
  3. 在腳本的頭部,添加您需要/想要隱藏介面的應用程式。作為例子,我設定:

    applications = ["gedit", "thunderbird"]
    
  4. 透過命令測試運行:

    python3 /path/to/password_app.py
    

    您需要密碼來隱藏和顯示您的介面:

  5. 如果一切正常,請將其新增至快速鍵組合:選擇:系統設定>「鍵盤」>「快速鍵」>「自訂快速鍵」。點擊“+”並新增命令:

    python3 /path/to/password_app.py
    

劇本

#!/usr/bin/env python3
import subprocess
import getpass
import os
import time

#---
applications = ["gedit", "thunderbird"]
#---

get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").strip()

def toggle():
    windowlist = os.environ["HOME"]+"/"+".windowlist.txt"
    user = getpass.getuser()
    wlist = [l for l in get("wmctrl -lp").splitlines()]
    procs = sum([[p.split()[0] for p in get("ps -u "+user).splitlines() if app in p] for app in applications], [])
    matches = sum([[l.split()[0] for l in wlist if p in l] for p in procs], [])
    if len(matches) != 0:
        with open(windowlist, "a+") as out:
            for match in matches:
                out.write(match+"\n")
                subprocess.Popen(["/bin/bash", "-c", "xdotool windowunmap "+match])
    else:
        try:
            with open(windowlist) as r:
                for l in r.readlines():
                    subprocess.Popen(["/bin/bash", "-c", "xdotool windowmap "+l])
            os.remove(windowlist)
        except FileNotFoundError:
            pass

try:
    cmd = "zenity --entry --title='Restricted!' --text='Enter your _password:'"
    passw = subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").strip()
    if passw == "Monkey":
        time.sleep(1)
        toggle()
except subprocess.CalledProcessError:
    pass

筆記

  • 這不會阻止用戶打開新實例的應用程序,它隱藏當前的應用程式。然而,所有這些都可以透過額外的編碼來完成:)。
  • 如果另一個使用者可能開啟列出的應用程式的新實例,則執行該腳本將首先將這些視窗新增至隱藏視窗。全部然後,視窗將在下次運行腳本時顯示。

答案2

旨在利用其他用戶權限的應用程序,例如System Settings-User accounts 做這個。

像 Thunderbird 這樣沒有這樣設計的應用程式不能開箱即用。因此你有兩種可能性:

  1. 擺脫你的程式設計技能並自行添加功能
  2. 為 Thunderbird 建立一個不同的用戶,並在su您需要閱讀郵件時進入該用戶,並在不閱讀郵件時將其關閉...

相關內容