[1.0.1] Env.getClipboard() seems to work only once and does not access real clipboard anymore after using paste()

Bug #769837 reported by RaiMan
54
This bug affects 10 people
Affects Status Importance Assigned to Milestone
Juno
New
Undecided
Unassigned
SikuliX
Fix Released
Medium
RaiMan

Bug Description

--1. 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.

--2. After using paste() the first time, Env.getClipboard() only returns the last pasted content, no matter what the "real" clipboard may contain.

-------------------------------------------------------------------------

I'm trying to get a few lines of text into variables in a for loop using Env.getClipboard() but it only works on the first loop.
On the second loopiteration Env.getClipboard seems to always return the last value of the first one.

I've checked the clipboard and the values are being correctly copied.

Any ideia what might be causing this? runing v. X-1.0rc2 Mac OS 10.6.7

Thanks in advance.

RaiMan (raimund-hocke)
summary: - using paste(): Env.getClipboard() does not access real clipboard anymore
+ X-1.0rc2: using paste(): Env.getClipboard() does not access real
+ clipboard anymore
description: updated
RaiMan (raimund-hocke)
summary: - X-1.0rc2: using paste(): Env.getClipboard() does not access real
- clipboard anymore
+ X-1.0rc3: Env.getClipboard() seems to work only once and does not access
+ real clipboard anymore after using paste()
description: updated
Revision history for this message
Dale King (dalewking) wrote : Re: X-1.0rc3: Env.getClipboard() seems to work only once and does not access real clipboard anymore after using paste()

I was running into similar problems yesterday on OSX. I was not doing any pasting.

What I was noticing when this was happening was not that Env.getClipboard() was failing to update to the new contents of the clipboard, but in fact somehow Sikuli was keeping the clipboard from working. When it got into this mode copy and pasting from one app to another was not working until I exited the IDE. I could select text in an app, hit CMD-C, and try to paste into another app and it would paste the clipboard before I hit copy.

But, unfortunately I can not reproduce this behavior today.

Revision history for this message
Jim White (jwhite-b) wrote :

Env.getClipboard() will get what was last copied in the IDE and will not change. The waits are not strictly necessary in the code below, but I was just making sure that I was not running into a race condition. To reproduce:

1. create an image around a text box that has text in it for clickPattern
2. in the sikuli IDE copy some text from below such as clickPattern.
3. run the below code
sikuli will print: bug:clickPattern instead of bug:text from step 1
if use cmd-v in any editor will be the correct text from step 1

    click(clickPattern)

    type("a",KEY_CMD)
    wait(1)
    type("c",KEY_CMD)
    wait(1)

    print "bug:" + str(Env.getClipboard())

Revision history for this message
Sid (scindiad) wrote :

I am having the same issue. Would this issue be fixed, anytime soon ?

RaiMan (raimund-hocke)
Changed in sikuli:
status: New → In Progress
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → x1.0
RaiMan (raimund-hocke)
tags: added: fkt-paste
RaiMan (raimund-hocke)
Changed in sikuli:
importance: Undecided → High
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: x1.0 → x1.1
Revision history for this message
Bunnings (sillybilly) wrote :

Just want to add that this issue is affecting my scripts as well.

RaiMan (raimund-hocke)
summary: - X-1.0rc3: Env.getClipboard() seems to work only once and does not access
+ [1.0] Env.getClipboard() seems to work only once and does not access
real clipboard anymore after using paste()
Revision history for this message
Philippe Trounev (ptrounev) wrote : Re: [1.0] Env.getClipboard() seems to work only once and does not access real clipboard anymore after using paste()

Hi Guys,
 The workaround for this is a custom Clipboard function using jython

from java.awt import Robot
from java.awt import Toolkit
from java.awt.event import KeyEvent

from java.awt.datatransfer import Clipboard
from java.awt.datatransfer import ClipboardOwner
from java.awt.datatransfer import DataFlavor
from java.awt.datatransfer import StringSelection
from java.awt.datatransfer import Transferable

robot = Robot()

toolkit = Toolkit.getDefaultToolkit()
clipboard = toolkit.getSystemClipboard()

def getClipboards():
    global clipboard
    return clipboard.getContents(None).getTransferData(DataFlavor.stringFlavor)
    customerID = getClipboards()
    subscriberID = getClipboards()
    orderID = getClipboards()

Usage is:
 getClipboards()

for example

If variable = getClipboards()
do this

or variable = getClipboards()
append it to file

etc....

RaiMan (raimund-hocke)
summary: - [1.0] Env.getClipboard() seems to work only once and does not access
+ [1.0.1] Env.getClipboard() seems to work only once and does not access
real clipboard anymore after using paste()
Revision history for this message
secwineman (nicolasbd) wrote :

Hi,
I'm experiencing the same behaviour with the paste function. As I needed this function (and I still do), I wrote a custom paste function months ago using Java classes. It perfectly works for me, but I must admit that I don't really know why, I found this solution empirically ... If you find why, maybe you'll find the solution.

PS : I tested the code above given by Philippe Trounev but unfortunately it didn't work for me. (Sikuli 1.0.1 x64 Linux/JDK 7u3).

RaiMan (raimund-hocke)
tags: added: testit
Revision history for this message
Linda (linda-nordstrom) wrote :

Hi,
I am also having problem with this.
Cannot get either Env.getClipboard() or the workaround getClipboards() by Phillippe above to work.. Tried to add different wait times but it doesn't matter, I still get the previous value in the clipboard, but when I try to paste manually after the test has run it pastes the new value.

Sikuli 1.1
Mac 10.7

Revision history for this message
Linda (linda-nordstrom) wrote :

But there are some weird stuff going on as well, it is not consistent. If I copy any text from Sikuli IDE (in my script), this will be the text that exists in the clipboard and will not get overwritten by the text that is copied when the script runs.
But if I have any text that has been copied from my app or safari, it all works fine..? The text gets replaced by the new text copied by my script..

RaiMan (raimund-hocke)
Changed in sikuli:
importance: High → Medium
milestone: 1.1.0 → 2.0.0
Revision history for this message
cometta (second-comet) wrote :

Any progress on this ?

RaiMan (raimund-hocke)
Changed in sikuli:
status: In Progress → Fix Released
milestone: 2.0.0 → none
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.