skip to Main Content

I have the following code that is automating a process in the browser.
At the line pt.click(clicks=3) I can get the text selected in the input box (Chrome). At the line pc.copy() I should copy this text and send it to the variable self.message to be processed. This step is not working.
There are a lot of documents and tutorials on how to do that on Windows and Mac, not in Ubuntu, specially in Ubuntu 22.04.

I am using OS Ubuntu 22.04 and Python 3.10.4.

What am I missing?

from turtle import right
import cv2 as cv
from time import sleep
# Waiting time
print('Waiting 2s')
sleep(2)

import pyautogui as pt
import paperclip as pc
from tkinter import ttk

....

def nav_message(self):
    try:
        clipPicCenter = pt.locateCenterOnScreen('./clip_pic.png', confidence=0.7)
        # print('LocateCenter clip_pic', clipPicCenter)
        pt.moveTo(clipPicCenter[0]+48, clipPicCenter[1]-60, duration=self.speed) 

        pt.click(clicks=3)
        sleep(.9)

        self.message = pc.copy() //Out PUT - Pyperclip do not have the method copy()
        print(self.message)

        # pt.click(button='right', clicks=1)
        # pos = pt.position()
        # pt.moveTo(pos[0]+20, pos[1]-300, duration=self.speed)
        # txt = pt.click()
        # print(txt)
        # self.nav_input_box()
        # pt.write(txt)
        # txt = pt.hotkey("ctrl", "c") # copy the text (simulating key strokes)
        # pt.click(button=right)
        

    except Exception as e:
        print ('Exception (nav_green_dot): ', e)

2

Answers


  1. you can use this to copy something to your clipboard

     import pyperclip
     s1 = "Hello world"
     pyperclip.copy(s1)
     s2 = pyperclip.paste()
     print(s2)
    
    Login or Signup to reply.
  2. Line 9 you import paperclip as pc. You need to import pyperclip as pc (Note that it starts with py and not pa). The 2 are spelled similar, but your code imports the paperclip library for Django instead of the pyperclip library for managing the clipboard. Heres a codeblock with your fixed imports:

    from turtle import right
    import cv2 as cv
    from time import sleep
    # Waiting time
    print('Waiting 2s')
    sleep(2)
    
    import pyautogui as pt
    # this used to be "paperclip"
    # "pyperclip" is what you need to import
    import pyperclip as pc
    from tkinter import ttk
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search