I have several Word documents (.docx) that must be marked up then run through a parsing engine.
For example, the (plain) text below should be changed to the new text.
Plain text
Now is the time for all good men to come to the aid of the party.
New texts some possibilities
Now is the time for all [[good men>> good]] to come to the aid of the party.
or
Now is the time for all [[@Label:good men]] to come to the aid of the party.
The formats of the markup syntax include
[[surface text>>scheme:reference]] or [[surface text>>position]]
[[@command:surface text]]
Apart from the [[ ]] delimiters, sometimes the surface text comes first, sometimes last.
My initial thoughts are to highlight the surface text (here=good men) then invoke say #z or #Z and have these ask for either scheme:reference or @command and then enter the appropriate keystrokes around the highlighted surface text.
Is this a good way? Is there a better way?
Which commands should I research, which tutorials?
Thanks
Len
Newbie: your keyword suggestions for this task
Started by
revver
, Aug 17 2012 12:57 AM
4 replies to this topic
#1
Posted 17 August 2012 - 12:57 AM
#2
Posted 17 August 2012 - 03:13 PM
Hi Len, your question has many parts. In order to answer them, we need to break them down.
Your first problem is that AutoHotKey cannot (alone) parse through .docx files. It just doesn't know how to read them. Try using a TXT editor to open a .docx file & you'll realize what I mean. So the first step would be trying to find a way to bridge the gap. do these files need to be in .docx to start? Maybe they can be TXT files which are later converted
Secondly, it seems that you want to do a basic string replace. Though you're not altogether clear on how the words will be chosen. Assuming it was a readable text document, I would do the following
Though it's not completely clear on what you want to do, based on what I've understood, this is how I would do it.
Your first problem is that AutoHotKey cannot (alone) parse through .docx files. It just doesn't know how to read them. Try using a TXT editor to open a .docx file & you'll realize what I mean. So the first step would be trying to find a way to bridge the gap. do these files need to be in .docx to start? Maybe they can be TXT files which are later converted
Secondly, it seems that you want to do a basic string replace. Though you're not altogether clear on how the words will be chosen. Assuming it was a readable text document, I would do the following
FileRead, OutputVar, %A_desktop%\test.txt ; GETS test.txt FROM THE DESKTOP & CONVERTS IT TO THE VARIABLE OutputVar StringReplace, outputvar, outputvar, good men, [[@Label:good men]], All ; REPLACES ALL 'good men' WITH '[[@Label:good men]]' FileDelete, %A_desktop%\test.txt ; DELETES THE ORIGINAL FILE FileAppend, %OutputVar%, %A_desktop%\test.txt ; WRITES NEW FILE TO LOCATION
Though it's not completely clear on what you want to do, based on what I've understood, this is how I would do it.
#3
Posted 17 August 2012 - 03:49 PM
If I were doing this I'd use Word and automate its built-in search and replace facility using AHK. First I'd build a word/phrase list in a simple text document containing the text I needed to search for and the indexing keyword for your [[PHRASE>>Keyword]] format. I'd make two copies of the docx, one in which I'd replace PHRASE with [[PHRASE>>Keyword]] and another in which I'd replace PHRASE with [[@Label:PHRASE]]. I'd use AHK to automate the repetitive copying of text from the 'word list' to Word's Search and Replace Box and executing the replace. Mind you, this could just as easily be done in a lot of text editors too (Wordpad springs to mind). If you didn't need to preserve any formatting, you could just save the docx as a text file.
#4
Posted 18 August 2012 - 02:38 AM
Thanks Sergio and ramagel,
I tried so hard to be clear yet succinct but I missed the mark. Sorry.
I saw no way of automating the entire process. Mostly, it requires a human to do three things-
1. choose/highlight which surface text will be modified (unknown ahead of time. It is context driven)
2. decide which method of modification to use,
a. the textfirst one [[surface text>>command]]
b. the textlast one[[@command:surface text]]3. Choose the specific command (from a list)[/list]
I thought of highlighting the text in Word and using #z to replace the chosen text with modified text based on responses to Q2 & Q3. This should maintain the docx stuff transparently.
Another possibility is to choose/highlight the surface text as before but then to choose a specific command and the script knows whether to use format a or format b and also which command paramaters are available for each command.
For example, numerals in the text may be marked thus
Page [[@Page:21]]
See Chapter [[21>>Position,21,1]] for more.
From my research so far, if either method is used, I will need the variable Clipboard and some code like this -
Thanks
I tried so hard to be clear yet succinct but I missed the mark. Sorry.
I saw no way of automating the entire process. Mostly, it requires a human to do three things-
1. choose/highlight which surface text will be modified (unknown ahead of time. It is context driven)
2. decide which method of modification to use,
a. the textfirst one [[surface text>>command]]
b. the textlast one[[@command:surface text]]3. Choose the specific command (from a list)[/list]
I thought of highlighting the text in Word and using #z to replace the chosen text with modified text based on responses to Q2 & Q3. This should maintain the docx stuff transparently.
Another possibility is to choose/highlight the surface text as before but then to choose a specific command and the script knows whether to use format a or format b and also which command paramaters are available for each command.
For example, numerals in the text may be marked thus
Page [[@Page:21]]
See Chapter [[21>>Position,21,1]] for more.
From my research so far, if either method is used, I will need the variable Clipboard and some code like this -
Prepend = [[
Append = ]]
Send ^c ;copy to clipboard
InputBox ;ask Q2
If ( ) {something}
If ( ) {something}
InputBox ;ask Q3
If ( ) {something}
If ( ) {something}
clipboard = %Prepend% %Clipboard% %Append%
Send %Clipboard% ;or Send ^v to pasteor like thisPrepend = [[
Append = ]]
Send ^c ;copy to clipboard
InputBox ;ask which command
If ( ) {something}
If ( ) {something} ; say Append = %command% %Append%
If ( ) {something} ; or %Prepend% %Command% etc
If ( ) {something}
clipboard = %Prepend% %Clipboard% %Append%
Send %Clipboard% ;or Send ^v to pasteAm I on the right track? I hope I have been clearer this time.Thanks
#5
Guests
Posted 18 August 2012 - 06:12 AM
You're right on the clipboard but for the user interaction I wouldn't use InputBox, but either:
- A simple MsgBox if you only have two options e.g. YES/NO
- A Menu with loads of options
- or a Gui which would also allow you to add additional info
- A simple MsgBox if you only have two options e.g. YES/NO
- A Menu with loads of options
- or a Gui which would also allow you to add additional info




