Copying multiple strings to clipboard from a tiddler

61 views
Skip to first unread message

Shankar Swamy

unread,
Aug 15, 2012, 7:11:30 PM8/15/12
to tiddly...@googlegroups.com


I am using the following code, by Eric, to copy a string to the clipboard.  I call " gdeSaveToClipboard(...)" shown below, with the appropriate argument, to copy a string to the clipboard.

If I called this function multiple times within the tiddler, it only copies the string passed to the last call and ignores the rest.

Is there a way to make this work for copying multiple strings to the clipboard?  For example, right now, I am using it for copying the name of the tiddler created to the clipboard.  I would like to copy the name of the tiddler as well as the time it was created separately to the clipboard. 

(In case you wonder, I have freeware utility called "Ditto" that let me access multiple items from the clipboard on Windows.)

Thank you for your help.

Cheers; 'best,
shankar swamy


function gdeSaveToClipboard(textToCopy) {
    function copy(out) {
                //alert("Copied: " + textToCopy);
        if(window.Components) { // FIREFOX
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            var id='@mozilla.org/widget/clipboardhelper;1';
            var clip=Components.classes[id].getService(Components.interfaces.nsIClipboardHelper);
            clip.copyString(out);
        } else if(window.clipboardData) { // IE
            window.clipboardData.setData('text',out);
        } else if(document.execCommand) { // CHROME, SAFARI, IE6
            var ta=document.createElement('textarea');
            ta.style.position='absolute';
            ta.style.left='-100%';
            document.body.appendChild(ta);
            ta.value=out; ta.select();
            document.execCommand('Copy',false,null);
            document.body.removeChild(ta);
        } else throw('cannot access clipboard');
    }
   
    try     { copy(textToCopy); }
    catch(e) { // FALLBACK
        alert('Copy to clipboard() failed - please copy the text manually.');
        }
}

TonyM

unread,
Aug 15, 2012, 10:22:28 PM8/15/12
to tiddly...@googlegroups.com
So to define your request would you say you want to append to clipboard ?

Daniel Baird

unread,
Aug 15, 2012, 10:42:59 PM8/15/12
to tiddly...@googlegroups.com

I'm not sure if the standard Windows system clipboard actually supports multiple clips.  I think you're asking how to programatically add things to the clipboard so that ditto can see them all?

I'd guess that ditto just watches the Windows clipboard and whenever it updates, saves the new thing off of it.  So assuming that your code selects text and copies it to the clipboard, running it multiple times should work fine.

First confirm definitely that your code really is putting text on the clipboard.

Perhaps ditto isn't "noticing" the clipboard updating.  What happens if you run your code, then manually select-and-copy some text in notepad, then run your code again?  Do you get three items in the ditto list?


;Daniel





--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/tiddlywikidev/-/FImlH-dZnBMJ.
To post to this group, send email to tiddly...@googlegroups.com.
To unsubscribe from this group, send email to tiddlywikide...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tiddlywikidev?hl=en.



--
Daniel Baird
I've tried going to the XHTML <bar /> a few times, but it's always closed.

Shankar Swamy

unread,
Aug 20, 2012, 2:48:59 AM8/20/12
to tiddly...@googlegroups.com


On Wednesday, August 15, 2012 7:42:59 PM UTC-7, Daniel Baird wrote:

I'm not sure if the standard Windows system clipboard actually supports multiple clips.  I think you're asking how to programatically add things to the clipboard so that ditto can see them all?

I'd guess that ditto just watches the Windows clipboard and whenever it updates, saves the new thing off of it.  So assuming that your code selects text and copies it to the clipboard, running it multiple times should work fine.

First confirm definitely that your code really is putting text on the clipboard.

Perhaps ditto isn't "noticing" the clipboard updating.  What happens if you run your code, then manually select-and-copy some text in notepad, then run your code again?  Do you get three items in the ditto list?


;Daniel

Right, you are!  In hind sight, I think I posted that question in a haste. All that I had to do was to insert an "alert(...)" in between two copies to see that both the first and the second copies do appear in the clipboard successively; but "... the ditto isn't noticing the first one..." as you said!  I looked into the source code of ditto which is a freeware project on sourceforge.com.  But right now it is more work than I can afford to devote to it.  So I will live with workarounds! :-(

Thanks for your times, everyone.

Cheers; 'best,
shankar
 
Reply all
Reply to author
Forward
0 new messages