Last active
March 6, 2019 11:36
Revisions
-
maximal revised this gist
Mar 6, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,7 @@ # @since 2019-03-06 # @copyright © MaximAL 2019 # @link https://gist.github.com/maximal/2387d023534a989cf2b3d68132807b67 # @link https://t.me/sijekotech/1853 # @link https://maximals.ru # @link https://sijeko.ru ## -
maximal revised this gist
Mar 6, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,4 +77,4 @@ for item in pyperclip.paste().splitlines(): out = subprocess.check_output([command, item]) logger.debug(out) logger.info('Command done') -
maximal revised this gist
Mar 6, 2019 . 1 changed file with 80 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,80 @@ #!/usr/bin/env python3 ## # Запуск произвольной команды над набором выбранных в файловом менеджере Nautilus файлов # # Удобно вешать действия над файлами на горячие клавиши в Линуксе. # # Использование: # Допустим, у нас есть команда или скрипт `/home/user/your/command`, что принимает первым аргументом имя файла для обработки. # Мы хотим запускать эту команду для каждого из выбранных в Наутилусе файлов. # # 1. Копируем этот скрипт себе допустим в `/home/user/run-on-selected.sh`, ставим ему права на запуск. # 2. Заходим в Параметры → Устройства → Клавиатура # 3. Добавляем свою комбинацию клавиш, пишем любое имя, в команде пишем: # /home/user/run-on-selected.sh '/home/user/your/command' # Таким образом можно настроить сколько угодно команд и горячих клавиш. # 4. Готово. # В файловом менеджере выделяем нужные файлы, нажимаем выбранную комбинацию. # В случае проблем смотрим журнал '/tmp/run-on-selected.log # # Зависимости: python3-pyperclip xdotool # Перед использованием надо установить эти. Например, в Debian/Ubuntu: # sudo apt install python3-pyperclip xdotool # # Если команда — текстовый скрипт, то вначале должен быть шебанг, иначе Питон её не запустит. См.: # @link https://stackoverflow.com/questions/27606653/oserror-errno-8-exec-format-error # # @author MaximAL # @since 2019-03-06 # @copyright © MaximAL 2019 # @link https://gist.github.com/maximal/2387d023534a989cf2b3d68132807b67 # @link https://maximals.ru # @link https://sijeko.ru ## import subprocess import pyperclip import time import sys import logging from urllib.parse import unquote # Логгер действий formatter = logging.Formatter('@%(asctime)s [%(levelname)s] $%(name)s @%(threadName)s: %(message)s') fhandler = logging.FileHandler('/tmp/run-on-selected.log', mode="a") fhandler.setLevel(logging.DEBUG) fhandler.set_name('file_handle') fhandler.setFormatter(formatter) logger = logging.getLogger(sys.argv[0]) logger.addHandler(fhandler) logger.setLevel(logging.DEBUG) # Поехали! logger.info('Command run') # Недостаточно аргументов (нужна команда для запуска) if len(sys.argv) < 2: print ('Usage: ' + sys.argv[0] + ' ' + '<command>') print ('Runs <command> on every file selected in Nautilus.') print ('<command> argument is mandatory.') logger.error('Error: <command> argument is mandatory') exit(1) command = sys.argv[1] logger.info(command) # Делаем паузу на всякий случай time.sleep(0.5) # Копируем имена файлов в буфер обмена subprocess.call(['xdotool', 'key', 'Control_L+c']) # Для каждого имени файла запускаем команду с аргументом for item in pyperclip.paste().splitlines(): logger.debug([command, item]) out = subprocess.check_output([command, item]) logger.debug(out) logger.info('Command done.') -
maximal created this gist
Mar 6, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ #