Author Topic: Getting a code and setting it to clipboard  (Read 1406 times)

How would I go about copying a code to the clipboard with a function?

For example if I typed into the console

getcode("Add-Ons/Server_Whatever/server.cs");

It would take the code from Add-Ons/Server_Whatever/server.cs and set it to my clipboard.
« Last Edit: March 01, 2012, 04:51:10 PM by Danny Boy »

I'm not sure if you can set strings to the clipboard with TS. I only know you can see what is currently stored with a command like getClipboard()

I'm not sure if you can set strings to the clipboard with TS. I only know you can see what is currently stored with a command like getClipboard()
setclipboard("Random stuff");


setclipboard("Random stuff");


As long as setClipboard is an actual function, then this will work.
Code: [Select]
function copyFileToClipboard(%file)
{

%string = "";
%file = new fileObject();

%file.openForRead(%file);

while(!%file.isEOF())

{

%string = %string SPC %file.readLine();
}

%file.Close();
%file.Delete();
setClipboard(%string);
}



look at setClipboard() and getClipboard() here: http://docs.garagegames.com/tge/official/content/documentation/Reference/Console%20Functions/TorqueScript_Console_Functions_13.html#setClipboard.28_string_.29

It might not work for your purposes, it looks like it operates through a GUI
test

I used setClipboard("test"); and ctrl v'd that in.

This will be very useful for me...

This will be very useful for me...
If you're talking about what I think you're talking about, then no, that won't work.

If you're talking about what I think you're talking about, then no, that won't work.
I don't know what you think I'm talking about

Snip
Thanks, I got that to work exactly how I wanted with a small change and it works great.

Code: [Select]
function copyFileToClipboard(%m)
{

%string = "";
%file = new fileObject();

%file.openForRead("Add-Ons/"@%m@"");

while(!%file.isEOF())

{

%string = %string SPC %file.readLine();
}

%file.Close();
%file.Delete();
setClipboard(%string);
}

So now I can type into my console:
copytoclipboard("Server_Whatever/server.cs");

And it worked out well :D

Code: [Select]
%file.openForRead("Add-Ons/"@%m@"");
The last @ and "" at the end is not needed.

The last @ and "" at the end is not needed.
I know but personally I just feel better doing it like that. I'm just awkward in that way :P

Also, this part:
Code: [Select]
while(!%file.isEOF())

{

%string = %string SPC %file.readLine();
}
Should turn into:
Code: [Select]
while(!%file.isEOF())
{

%string = %string $= "" ? %file.readLine() : %string SPC %file.readLine();
}

So that the first character of %string isn't a space.

Or he could just change SPC to @.

Why SPC?

Aren't they new lines?