노틸러스 스크립트에 키보드 단축키를 할당하려면 어떻게 해야 합니까?

노틸러스 스크립트에 키보드 단축키를 할당하려면 어떻게 해야 합니까?

나는노틸러스 스크립트. 스크립트를 넣었 /home/sumeet/.local/share/nautilus/scripts더니 오른쪽 클릭 메뉴에 나타납니다. 또한 예상대로 작동합니다. 스크립트에 바로가기를 지정하고 싶습니다.


노틸러스 스크립트에 대한 키보드 단축키를 어떻게 만들 수 있나요?

위 질문에 제공된 답변은 특정 릴리스를 대상으로 하며 완전히 구식이며 이 주제에 관한 이 질문 외에는 찾을 수 없습니다.

답변1

어떻게 할 수 있습니까?

노틸러스 스크립트의 파일이나 폴더를 마우스 오른쪽 버튼으로 클릭하면 선택한 파일이 스크립트에 인수로 전달됩니다. 대부분의 경우 다음과 같습니다.

import os
subject = os.getenv("NAUTILUS_SCRIPT_CURRENT_URI")

...가장 간단한 형태로 python3을 사용합니다.

이것을 다음과 같이 바꾸면:

import pyperclip

subprocess.call(["xdotool", "key", "Control_L+c"])
subject = pyperclip.paste()

...현재선택된파일은 스크립트 내에서 인수로 사용됩니다.

필요한 것

이 솔루션(16.04 이상)을 사용하려면 xdotool및 다음을 모두 설치해야 합니다 python3-pyperclip.

sudo apt-get install python3-pyperclip xdotool

주석에 언급된 전체 스크립트

그러면 다음과 같이 됩니다:

#!/usr/bin/env python3
import subprocess
import os
import sys
import pyperclip

# --- set the list of valid extensions below (lowercase)
# --- use quotes, *don't* include the dot!
ext = ["jpg", "jpeg", "png", "gif", "icns", "ico"]
# --- set the list of preferred filenames
# --- use quotes
specs = ["folder.png", "cover.png", "monkey.png"]
# ---

# retrieve the path of the targeted folder
subprocess.call(["xdotool", "key", "Control_L+c"])
dr = pyperclip.paste()

for root, dirs, files in os.walk(dr):
    for directory in dirs:
        folder = os.path.join(root, directory)
        fls = os.listdir(folder)
        try:
            first = [p for p in fls if p in specs]
            first = first[0] if first else min(
                p for p in fls if p.split(".")[-1].lower() in ext
                )
        except ValueError:
            pass
        else:
            subprocess.Popen([
                "gvfs-set-attribute", "-t", "string",
                os.path.abspath(folder), "metadata::custom-icon",
                "file://"+os.path.abspath(os.path.join(folder, first))
                ])

이것을 바로 가기 키에 추가하면 모든 디렉토리에 대한 아이콘이 설정됩니다내부에선택한 것.

단축키에 추가(!)

단축키 추가, xdotool누르는 명령 실행(-를 사용하는 스크립트)또 다른키 조합이 까다로울 수 있습니다. 두 키 조합이 서로 간섭하지 않도록 하려면 다음을 사용하십시오.

/bin/bash -c "sleep 1 && python3 /path/to/script.py"

설명

파일을 선택한 상태에서 Ctrl+를 누르면C파일이 클립보드에 복사됩니다. 다음을 사용하여 키 누름을 시뮬레이션합니다.

subprocess.call(["xdotool", "key", "Control_L+c"])

python의 모듈은 사용할 때 pyperclip제거된 경로를 생성합니다 (문자 그대로 붙여넣는 것이 아니라 스크립트 내에서 경로를 사용할 수 있게 만듭니다).file://pyperclip.paste()

답변2

파일을 선택하고 작업을 실행하는 것이 목표인 경우 xdotool및 셸 스크립트만 사용하여 수행할 수 있습니다 xclip. 먼저 설치하십시오.

sudo apt-get install xdotool xclip

그런 다음 루프 내부의 작업을 사용하여 다음 스크립트를 만듭니다.

#!/bin/bash
file=$(mktemp)

xdotool key "Control_L+c"
variable="$( xclip -out -selection clipboard)"
variable="$( echo -e "$variable" | \
            awk 'BEGIN { FS = "\n" } { printf "\"%s\" ", $1 }' | \
            sed -e s#\"\"## | \
            sed 's/" "/"\n"/g')"

echo "$variable" > $file

if [ -s "$file" ]; then
   while read absolute_path_file; do
      absolute_path_file="$(eval echo "$absolute_path_file")"
      base_name="$(basename "$absolute_path_file")"
      ### Execute the actions with the selected files here
      ### echo "$absolute_path_file"
      ### echo "$base_name"
   done < $file
fi

이 스크립트는 NAUTILUS 변수에 의존하지 않으며 이를 사용하여 바로가기를 만들 수 있습니다.

/bin/bash -c "sleep 1 && /path/script.bash"

답변3

  • 절차 사용여기에 설명되어 있습니다를 사용하면 노틸러스 스크립트에 노틸러스의 바로가기를 추가할 수 있습니다. 이것은 Nautilus 40부터 다시 작동합니다.
  • _노틸러스 스크립트 이름을 사용하면 스크립트에 단축키를 할당할 수 있습니다. 예를 들어 "_Combine PDF"라는 스크립트는 밑줄이 그어진 C와 함께 표시됩니다. 파일이 선택되면 Shift+를 사용하여 스크립트에 빠르게 액세스할 수 있습니다 F10 c.

하위 폴더에 스크립트를 구성할 수 있습니다. 이러한 하위 폴더는 메뉴 선택 항목으로도 나타나며 하위 메뉴로 연결됩니다. 또한 이 명명 규칙을 사용하여 단축키를 할당할 수도 있습니다.

관련 정보