Copy text through WriteLn

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Copy text through WriteLn

Post by winstein » Wed Jan 02, 2013 4:23 am

How do I implement copied text into a text file through WriteLn?

Thanks for reading.
PPQ

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 02, 2013 9:43 am

WriteLn writes text to the end of a text file.

Feel free to elaborate on your question but I'm guessing that what you want to do is modify a file by inserting text somewhere in the middle - i.e. not at the end of the file.

To do that what you would normally do is read the file in first using ReadFile. Then use string manipulation using e.g. RegEx/StringReplace/Position/MidStr and you may or may not use a loop, so that you end up with a large string which is what you want your updated file to contain.

So finally you would delete the old file, then write out the new chunk of text to file using WriteLn using the old filename (or use a new filename and do the delete and rename later).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Thu Jan 03, 2013 2:23 am

What I meant is that, after you copied the text (say, after pressing Ctrl + C), then I want to use this copied text and put it into a file directly, without the need to open the file and paste it. Basically pasting the content at the end of the file without actually opening the file. Would that be possible?
PPQ

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 03, 2013 3:56 am

Code: Select all

//get text from the clipboard and assign it to the variable "data"
GetClipBoard>data
//Write the value of "data" to a file
WriteLn>%temp_dir%clipboard_text.txt,wres,data

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Thu Jan 03, 2013 6:33 am

JRL wrote:

Code: Select all

//get text from the clipboard and assign it to the variable "data"
GetClipBoard>data
//Write the value of "data" to a file
WriteLn>%temp_dir%clipboard_text.txt,wres,data
Thanks for the advice!
PPQ

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts