pbcopy in Python to copy to the clipboard on OSX?

620 views Asked by At

I am receiving the following error when trying to use pbcopy to add the output to the clipboard. I tried different variations of the command and still no luck. Does anyone have any ideas where I may have failed?

Error Screenshot:

enter image description here

#!/usr/bin/env python3
# This script creates a secure password using all available key combinations.

import secrets , string, os

def prRed(skk): print("\033[91m {}\033[00m" .format(skk))

chars = string.ascii_letters+string.punctuation+string.digits # Cleaner way of assigning variable

print()
pwd_length = int(input('Enter the length of the desired password: '))

print()
print('[+] ' + 'Your secure password is:')
print()

for n in range(1):
    output = ""
    for i in range(pwd_length):
        next_index = secrets.SystemRandom().randrange(len(chars))
        output = output + chars[next_index]
    prRed(os.system("echo '%s' | pbcopy" % output))
print()
0

There are 0 answers