Jump to content


Photo

[SOLVED]Trying to substitute Loop Read with Loop Parse


  • Please log in to reply
6 replies to this topic

#1 RoseCode

RoseCode
  • Members
  • 16 posts

Posted 12 August 2012 - 01:46 PM

Hello,

This script works great with Loop Read File but when I switch to Loop Parse Clipboard, no luck. For One Key Testing I programmed the Right Ctrl key to save, reload and launch script :-) I'm also using DebugView instead of Msgbox. Just get it, launch it, and it will scroll any OutputDebug comment in your script :-) <!-- m -->http://technet.micro... ... 96647.aspx<!-- m -->

Here is the substantive part of the Loop Read Version:

F1= C:\temp\urls\url_input.txt
F2= C:\temp\urls\url_output.txt
Filedelete,%F2%
A=http://
T=
Loop,Read, %F1%

The Loop Parse Clipboard Version is the same except it uses the clipboard and Loop Parse. Why is Loop, Parse, Clipboard, not passing data to the loop in the same way as Loop, Read, does? Thank you!

;††† Open All Urls ††† 
;For FireFox users who need to free up Memory ;by closing 
;and restarting Firefox. Use "Copy All Urls" Firefox Plugin
;to copy all tabs to clipboard. Restart FireFox.
;Hit WindowsKey-U and all URLs on clipboard will open in tabs
;#u::

RCtrl::   ;;;  For Quick Testing right control saves, reloads and launches this script
send ^s
sleep 300
Reload

gosub proceedplease

proceedplease:


clipboard = 
(
http://en.wikipedia.org/wiki/Democratic_peace_theory
http://en.wikipedia.org/wiki/Never_at_War
Never at War - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Category:Lists_of_massacres_by_country
Category:Lists of massacres by country - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Persecution_of_Hindus
Armenian Genocide
http://en.wikipedia.org/wiki/Armenian_Genocide
The Armenian Genocide[4] (
The Young Turks' Crime Against Humanity:
The Armenian Genocide and Ethnic Cleansing in the Ottoman Empire
http://press.princeton.edu/titles/9678.html
http://en.wikiquote.org/wiki/Greek_genocide
Greek Genocide
)
;Outputdebug, clipboard is %clipboard%
;msgbox clipboard is %clipboard%
;links = %Clipboard%
;Outputdebug, links are %links%
;msgbox, links are %links%
clipwait 1
A=http://
T=
Loop, Parse, Clipboard  ;;; (changed from ****** Loop,Read, FileName ****** to use clipboard instead)
{
OutputDebug, is this empty? %A_LoopReadLine%
T=%A_LoopReadLine%
;OutputDebug, T is %T%
StringReplace t,T,.%A_Space%,`,,All
StringRight r,t,1
IfEqual r,., StringTrimRight t,t,1
Loop Parse,t,`,` `"`>`=`;?`!
     {
   StringLeft r,A_LoopField,7
   If r=%A%
;OutputDebug, %A_LoopField%
;OutPutDebug, hello there
   run,%A_LoopField%
     }
}

return

^esc::exitapp ;;;; Emergency Stop
return



#2 dylan904

dylan904
  • Members
  • 706 posts

Posted 12 August 2012 - 02:43 PM

1. You have to tell it what delimeter you are using to parse (`n to parse every line).

2. Everywhere you used A_LoopReadLine, you would replace it with A_LoopField, and considering you used Parses within the same thread, you might want to append the value of the first A_LoopField to another variable because its value will be lost upon the 2nd parse.

3. When parsing, you may want to use a different variable than the clipboard to apply the links to at the beginning of your paste, unless your reasoning determines otherwise.

#3 RoseCode

RoseCode
  • Members
  • 16 posts

Posted 12 August 2012 - 04:55 PM

1. You have to tell it what delimeter you are using to parse (`n to parse every line).

2. Everywhere you used A_LoopReadLine, you would replace it with A_LoopField, and considering you used Parses within the same thread, you might want to append the value of the first A_LoopField to another variable because its value will be lost upon the 2nd parse.

3. When parsing, you may want to use a different variable than the clipboard to apply the links to at the beginning of your paste, unless your reasoning determines otherwise.


Hi Dylan. I had already tested many variations of delimiters including your suggestion, prior to posting here. None worked and since all the parsing seems to be written into the body of the loop further down, where %A% is the delimiter, I presumed the working prototype by Laszlo had it right:
http://www.autohotke...pic.php?p=68856 It's the Script near bottom posted by Garry, originally from Laszlo.

I've attached a self contained version that writes links to a file and then feeds this file to Line 47. Works great. I want to only change Line 47, which has no delimiter because the body of the Loop does that work using the variable %A% as the delimiter.

If Laszlo's script works wonderfully as is using data from a file, there must be some way to use the exact same loop body, only fed with clipboard data in the form of "Loop, Parse, Clipboard".

Why not?




;------ script from LASZLO ------------
/*
F1=URLORIG.TXT
*/

RCtrl:: 

F1 = c:\temp\highly_unusual_filename_42zz.txt
F2=c:\temp\highly_unusual_filename_43zz.txt

Ifexist, %F2%
{
Filedelete, %F2%

}
;FileAppend, Hello, %F2%

wiki_links = 
(
http://en.wikipedia.org/wiki/Democratic_peace_theory
http://en.wikipedia.org/wiki/Never_at_War
Never at War - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Category:Lists_of_massacres_by_country
Category:Lists of massacres by country - Wikipedia, the free encyclopedia
http://en.wikipedia.org/wiki/Persecution_of_Hindus
Armenian Genocide
http://en.wikipedia.org/wiki/Armenian_Genocide
The Armenian Genocide[4] (
The Young Turks' Crime Against Humanity:
The Armenian Genocide and Ethnic Cleansing in the Ottoman Empire
http://press.princeton.edu/titles/9678.html
http://en.wikiquote.org/wiki/Greek_genocide
Greek Genocide
)

sleep 300
Ifexist, %F1%
{
Filedelete, %F1%
}
;OutputDebug, Proceed Please2
sleep 300
fileappend, %wiki_links%, %F1%
;OutputDebug, Proceed Please3
A=http://
T=
Loop,Read, %F1% ;;;;;;;;;;;;;;;;; This is the only line I should have to replace wtih Loop, Parse, F1
{
T=%A_LoopReadLine%
StringReplace t,T,.%A_Space%,`,,All
StringRight r,t,1
IfEqual r,., StringTrimRight t,t,1
Loop Parse,t,`,` `"`>`=`;?`!
     {
   StringLeft r,A_LoopField,7
   If r=%A%
   fileappend,%A_LoopField%`r`n,%F2%
     }
}

run, %F2%
return

RAlt::Reload

return





#4 Guests

  • Guests

Posted 12 August 2012 - 09:12 PM

He already gave you the answer!
Loop, Parse, Clipboard[color=#BF0000], `n[/color]


#5 RoseCode

RoseCode
  • Members
  • 16 posts

Posted 13 August 2012 - 05:14 PM

1. You have to tell it what delimiter you are using to parse (`n to parse every line).

2. Everywhere you used A_LoopReadLine, you would replace it with A_LoopField,

******and considering you used Parses within the same thread, you might want to append the value of the first A_LoopField to another variable because its value will be lost upon the 2nd parse.


THANKS DYLAN!!! For some reason, when I first tried your suggestions, some oversight on my part kept my script from working. With careful use of DebugView, and about 4 hours (sad I know) I got it working THANKS TO YOU. You helped me understand that Loop, Read has an automatic line parsing function built in, whereas Loop, Parse, Variable - does not. Initially I thought, except for differences in data source, they functioned the same. I was soooo wrong :-)

On losing the data in the 2nd parse, I haven't had that problem.

Thank you very much!

#6 dylan904

dylan904
  • Members
  • 706 posts

Posted 13 August 2012 - 05:40 PM

Okay great!
If you have no further questions concerning this post, please add the prefix [Solved] to the beginning of your post topic.

#7 RoseCode

RoseCode
  • Members
  • 16 posts

Posted 14 August 2012 - 06:36 PM

Okay great!
If you have no further questions concerning this post, please add the prefix [Solved] to the beginning of your post topic.


Hi Dylan,

Oh...okay...I haven't come up to speed on the protocols here yet. I'll do that right now.

Thank you again. I think this, and the Cockos Reaper DAW (Digital Audio Workstation) forum are the two most civilized and helpful forums on the planet. AutoHotKey has truly helped me to avoid Carpel Tunnel Syndrome. It's such a HUGE BLESSING. Thank you and Christ and Polythene, et al. for this wonderful asset :-)