Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Copying and pasting text displayed in OpenSesame into a different program

edited September 2014 in OpenSesame

Hello,

I am relatively new to OpenSesame and just struck a problem - would appreciate any help I can get! I am trying to run an experiment with a variety of tasks - including one about virtual worlds, which would have to be interlaced with all the rest.

A set of online virtual environments (VEs) would be selected for the experiment, and participants would be shown one of them randomly, and they would then have a predetermined length of time to explore it. Since these VEs would be outside OpenSesame, I would like participants to simply be shown the URL for each, which they could then copy and paste into another program to access them. This would save some time and reduce the margin for error when participants would search for the environments.

The problem, however, is I can't seem to get OpenSesame to allow copying and pasting, either from a sketchpad item, or a form, as they are being displayed during the experiment... Ideally, during the experiment I would have liked a sketchpad (or anything, really) to appear with the VE's URL written on it, which participants could then simply copy and paste into a different program...

Any advice would be much appreciated!
Many thanks!
AC

Comments

  • edited 6:44PM

    Hi,

    You cannot easily copy stuff from an OpenSesame experiment to the clipboard, because what you see during an experiment is essentially a slideshow of pictures, which the operating system doesn't know how to copy/paste from.

    In your case, would it be sufficient to have OpenSesame launch a browser automatically with a specific URL? That might even be more convenient for the user, and is much easier to implement. You can see an example of that in this discussion:

    Cheers!
    Sebastiaan

  • edited August 2014

    Thanks loads!
    Based on that example, I was able to find this solution for instance:

    import subprocess
    
    if self.get('open_cogsci') == 'yes':
    
        subprocess.Popen(['C:\Program Files (x86)\CtrlAltStudio-Viewer-Alpha\CtrlAltStudio-Viewer-Alpha.exe', 
    'http://maps.secondlife.com/secondlife/Psycho%20Chaos/114/163/806'])
    

    ...This is because in my case the program to be launched is not a regular internet browser, but a SecondLife viewer... Even if the current solution works, the problem now becomes that it does so only by opening more instances of the viewer, instead of changing the URL in the same viewer. Since my experiment would contain quite a few virtual environments, this would become a problem very fast... Could you please help with finding a way to just change the URL without opening more instances of the subprocess?

    I considered something like this:

    import webbrowser
    
    BROWSER=webbrowser.get('C:\Program Files (x86)\CtrlAltStudio-Viewer-Alpha\CtrlAltStudio-Viewer-Alpha.exe')
    
    if self.get('open_cogsci') == 'yes':
    
        BROWSER.open('http://maps.secondlife.com/secondlife/Psycho%20Chaos/114/163/806', new=0)
    

    ...which of course doesn't work, as I don't really know what I am doing... :-D

    Again, any help would be deeply appreciated!
    Thanks for the previous suggestion and all your work with OpenSesame in general!
    AC

  • edited 6:44PM

    Even if the current solution works, the problem now becomes that it does so only by opening more instances of the viewer, instead of changing the URL in the same viewer.

    This depends on the behavior of the program. Most webbrowsers will check to see if another instance is already running, and, if so, open the url in a new tab within an existing instance. But apparently the software that you use doesn't do that.

    In that case, you may want to use the clipboard like you initially had in mind. But you'll need to install some module so that you can copy stuff to the clipboard, such as pyperclip. You should be able to download the source file (see link below), and extract the pyperclip folder within it (so the folder with only an __init__.py file in it) to the OpenSesame program folder. Once you've done that, you should be able to access the clipboard as shown in the examples on the pyperclip page.

    Cheers!
    Sebastiaan

  • edited 6:44PM

    Hi,

    Thanks again for your help! I really appreciate it. :)

    Coincidentally, it seems that an upgraded version of CtrlAltStudio does check if an instance is already running, or at least that's what I infer from what happened: I upgraded a couple of days ago and now the URLs get changed in the same instance of the viewer...

    Hopefully my assumption is correct and now it will keep working with the code I provided above!

    I will keep pyperclip in mind though, might come in handy in the future!

    Thanks again!
    Caterina

  • edited 6:44PM

    Love it when a problem solves itself! Marking this as solved.

Sign In or Register to comment.