topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 1:32 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Line to clip  (Read 5239 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Line to clip
« on: December 02, 2012, 07:54 AM »
I need a little script for :

1) I have a txt file. by example :

This is the first line
This is the second line
https://www.donationcoder.com (this is the third line)
projects and advice (4)
......

2) I would like a script to convert in clips to the clipboard every line.

3) I have a txt file or similar, by example :

*
This is the first line
www.codingsnacks.tk
*
This is the second line
Post new requests here
*
This is the third line
https://www.donationcoder.com
*
projects and advive (4)

..........................
The goal is copy to the clipboard all the chain under the *
So I would like a script to read a txt file or similar and copy the lines or phrases under * to the clipboard.


4) Note : What I try to do later with this is not now the purpose. But the aim is inmediately I have one line or phrase in the clipboard execute another script to add as a register to a database.

Best Regards

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #1 on: April 10, 2013, 12:06 PM »
Hey Contro,

Not sure if you still needed this or not (since it's dated Dec 2012) so I'll kill two birds with one proverbial stone.

1.) My first post on the forums and hey to everyone!  "Hey" o/
2.) To address your needs

Code: Autohotkey [Select]
  1. ;FileDelete, output.txt  ;deletes the output file -- uncomment along with FileAppend below if you so chose
  2. FileRead, Contents, %A_ScriptDir%\clip.txt  ;place your text file with *'s in this directory & change name from clip.txt to anything
  3.         if not ErrorLevel
  4.         {
  5.                 set_f=0
  6.                 loop, parse, Contents, `n, `r
  7.                 {
  8.                         if (set_f=="1")
  9.                         {
  10.                                 ;FileAppend, %A_LoopField%`n, output.txt  ;uncomment this line to create an output file
  11.                                 msg_output .= A_LoopField . "`n"
  12.                                 set_f=0
  13.                         }
  14.                        
  15.                         if (A_LoopField=="*")
  16.                                 set_f=1
  17.                 }
  18.         }
  19. clipboard := msg_output  ;sets lines after * equal  to clipboard

Hope this helps!
~BigVent
« Last Edit: April 10, 2013, 01:20 PM by BigVent, Reason: added exitapp »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #2 on: April 10, 2013, 02:50 PM »
 ;D

Welcomeeeeeee !!!!!!!!!!!

I try and comment.

Best Regards
 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #3 on: April 27, 2013, 07:57 PM »
Is not what i need. I see only a window.

 :-[

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #4 on: April 27, 2013, 08:37 PM »
Save the quote below as "clip.txt" in the same folder as your ahk or exe.

It works here on three different OS's.  Can anyone else confirm?

*
This is the first line
www.codingsnacks.tk
*
This is the second line
Post new requests here
*
This is the third line
https://www.donationcoder.com


~BigVent
~BigVent

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #5 on: April 28, 2013, 02:06 PM »
I'll try and comment.
Best Regards
 :-*

BigVent

  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • View Profile
    • Donate to Member
Re: Line to clip
« Reply #6 on: April 29, 2013, 01:11 PM »
To verify the code above works correctly:


Code: Autohotkey [Select]
  1. var =
  2. (
  3. *
  4. This is the first line
  5. www.codingsnacks.tk
  6. *
  7. This is the second line
  8. Post new requests here
  9. *
  10. This is the third line
  11. http://www.donationcoder.com
  12. *
  13. 4th line in file
  14. blah blah
  15. more junk
  16. *
  17. 5th line in file
  18. blah blah more
  19. junk
  20. junk
  21. )
  22.  
  23. set_f=0
  24. loop, parse, var, `n, `r
  25. {
  26.         if (set_f=="1")
  27.         {
  28.                 msg_output .= A_LoopField . "`n"
  29.                 set_f=0
  30.         }
  31.         if (A_LoopField=="*")  ;if line equals * per request... the next line is obtained -- append to variable
  32.                 set_f=1
  33. }
  34. msgbox % msg_output
  35.    exitapp


Enjoy!

~BigVent
~BigVent