Env.getClipboard is not updated

Asked by Sleek

Hi,

I want to copy text that is inside a text area to clipboard.

I set the focus to textarea and then select the whole contents with CMD+a (I am on a Mac) and then copy the selection with CMD+c. When I call Env.getClipboard() I get the previous content of the Clipboard and not the new copied text. I do know that the clipboard was updated since if I paste (not using Sikuli) the new content is pasted.

I use Interactive Sikuli Jython Session to do all this, if I relaunch it and check Env.getClipboard it has the new content. So it seems like Env.getClipboard only gets updated at the start.

Is this a bug?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Yes, it is a bug.

But until now, I thought it would only stop to work as expected, when intermixing with paste() ???

Revision history for this message
Sleek (sleekism) said :
#2

Yes you are correct, I did use paste before doing a copy. Thank you for pointing me to the bug report. I will try to replace paste() with type().

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Hope you know the restrictions of type() and they do not affect you ? faq 933

all the best.

Revision history for this message
Sleek (sleekism) said :
#4

Thankfully those restrictions do not apply to me :)

Revision history for this message
Robert Feldt (robert-feldt) said :
#5

A workaround on Mac that I sometimes found helpful is to use the following code to save (or append with fileFlag 'a') the Mac's clipboard contents to a file:

def save_mac_clipboard_to_file(filename, fileFlag = 'w'):
    if fileFlag == 'w':
        os.system('pbpaste > ' + filename)
    elif fileFlag == 'a':
        os.system('pbpaste >> ' + filename)

Especially if one was planning to save the contents to file anyway; with this code you need not go "through" Sikuli and get the associated Env.getClipboard problems. However, one can fully work around the bug by first using the above code to save to a (temporary) file and then read that files contents into a string in Sikuli...

Can you help with this problem?

Provide an answer of your own, or ask Sleek for more information if necessary.

To post a message you must log in.