This is a Python script, written in Python 3.6.1, does not work in Python < 3.6.0. If you want to use it for lesser versions, replace the f-strings such:
Code: Select all
f'{Variable1}{Variable2}' => '{}{}'.format(Variable1, Variable2)
Code: Select all
from sys import argv
from os import path
from shutil import copy
Path = '/home/<your_path>'
if '-i' in argv:
File = 'important_file'
else:
File = 'other_file'
New = f'{File}.txt'
fNum = 0
while path.exists(path.join('.', New)):
fNum += 1
New = f'{File}_{fNum}.txt'
copy(path.join(Path, f'{File}.txt'), New)
It seems, however, that we can't go completely without Bash, so here's what I do next:
Shell script one: "Copy Normal File to Current Directory" (no extension used)
Code: Select all
#! /usr/bin/env bash
/<your_path_to_python>/Python3/python /home/<your_path_to_python_script>/CopyInPython.py
Code: Select all
#! /usr/bin/env bash
/<your_path_to_python>/Python3/python /home/<your_path_to_python_script>/CopyInPython.py -i
This was just a simple example. I'm sure you can conjure up new ideas on how to use this recipe.
Python is, IMO, far easier to write than Bash scripts!
Have fun!
(Oh, and since I use a very old version, Caja might be able to run Python directly now, I don't know, I didn't bother looking before I posted this. Anyway, there might be people out there that use old versions, too. :)
Here's some additional code, for those who still live in the dark.
This copies filenames to the clipboard:
Code: Select all
#! /usr/bin/env python361
'''Script name: copy_filename.py'''
from sys import argv
from os import environ, path
import pyperclip
qs = ''
result = []
illegals = [' ', '!', '(', ')', '[', ']', '?', '*'] #add more of them as you find them
def make_escaped(what):
''''''
result = ''
for c in what:
if c in illegals:
result += '\\' + c
else:
result += c
return result
if '-q' in argv:
qs = '"'
sel_files = environ['CAJA_SCRIPT_SELECTED_FILE_PATHS'].strip()
if '-e' in argv:
sel_files = make_escaped(sel_files)
if '-f' in argv:
#only filename
for f in sel_files.split('\n'):
fn = path.split(f)[1]
result.append(f'{qs}{fn}{qs}')
pyperclip.copy('\n'.join(result).strip())
else:
#full path
fn = sel_files
pyperclip.copy(f'{qs}{fn}{qs}')
Python 3.6+ (or you can rewrite it as previously stated for lesser versions)
Python package pyperclip (google "python pyperclip" and you should find it, if you don't want to bother with installing it, put its source script directory in the same directory as the Python script above, that ought to work)
The following Bash scripts (i.e., one for each command):
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Escaped Filename to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py -f -e
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Escaped Full Path to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py -e
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Filename to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py -f
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Full Path to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Quoted Filename to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py -f -q
Code: Select all
#! /usr/bin/env bash
#Script name: Copy Quoted Full Path to Clipboard
/home/<your path>/Python-3.6.1/python /home/<your path>/Programming/Python/CajaScripts/copy_filename_to_clipboard/copy_filename.py -q