尝试运行与密钥链接的 /home/andy/bin/python3 paste_snippets.py 时出错

尝试运行与密钥链接的 /home/andy/bin/python3 paste_snippets.py 时出错

我创建了键盘快捷键。但是当我尝试运行它时却收到此消息。

Error while trying to run /home/andy/bin/python3 paste_snippets.py which is
linked to the key(<Primary>Alt>a)

主要的实际上是 Ctrl 键。


#!/usr/bin/env python3

import os
import subprocess

home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
    os.mkdir(directory)
# create file list with snippets
files = [
    directory+"/"+item for item in os.listdir(directory) \
         if not item.endswith("~") and not item.startswith(".")
    ]
# create string list
strings = []
for file in files:
    with open(file) as src:
        strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
    (str(i+1)+". "+strings[i].replace("\n", " ").replace\
     ('"', "'")[:20]+"..") for i in range(len(strings))
    ]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
      .join(list_items)+'"'\
      +' --column="text fragments" --title="Paste snippets Ctrl V"'
# process user input
try:
    choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
    if "manage snippets" in choice:
        subprocess.call(["nautilus", directory])
    else:
        i = int(choice[:choice.find(".")])
        # copy the content of corresponding snippet
        copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
        subprocess.call(["/bin/bash", "-c", copy])
        # paste into open frontmost file
        paste = "xdotool key Control_L+v"
        subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
    pass

在此处输入图片描述

它在 16.04 中运行良好,但在 18.04 中却不行。

难道我做错了什么?

7/18/18 从命令行运行时。

即使窗口弹出,我得到的只是

Gtk-Message: 21:23:49.927: GtkDialog mapped without a transient parent.         
This is discouraged.

答案1

我不得不更换这一行

   subprocess.call(["nautilus", directory])

    subprocess.call(["thunar", directory]) 

我没有 nautilus,但使用 thunar 作为我的文件管理器。

相关内容