UAMike Posted November 15, 2017 Report Share Posted November 15, 2017 I am trying to figure out a way to modify a long string variable (a paragraph or two of text) while the macro is running and then use the updated variable downstream in the macro. I want to be able to delete phrases, words, adjust spacing, etc, so any of the 'Variable Modify String' functions will not do the trick. I think I can get this done by having the macro paste the string into a notepad document, then I would do my manual edits, then copy the text to the clipboard and set the variable to the clipboard contents. Ideally I wouldn't have to fiddle around with this clipboard/notepad method, but I am not sure if there is an easier/better way. Any suggestions? Quote Link to comment Share on other sites More sharing options...
Cory Posted November 15, 2017 Report Share Posted November 15, 2017 I've used Variable Set String like this in the past but this is too much. I think Notepad is your best bet. I wouldn't paste however. I'd use Windows Controls commands. Quote Link to comment Share on other sites More sharing options...
rberq Posted November 15, 2017 Report Share Posted November 15, 2017 It's hard to say without knowing specifically what edits are required -- but Variable Modify String commands can accomplish a lot, so that would be my first choice. Without some examples, I don't know why you feel it won't work. As a second choice, paste the data into Notepad as you propose, but have your macro run as many of the edit commands as possible, rather than do them manually. That's a lot faster than you can type, and a lot less drudgery, as long as the same rote commands can be used every time. If there's some THINKING involved for special situations, handle those situations manually after the macro has done its work. Quote Link to comment Share on other sites More sharing options...
acantor Posted November 16, 2017 Report Share Posted November 16, 2017 I use Variable Modify String commands a lot to revise texts. For example: Text Type (Simulate Keystrokes): <CONTROL>a // Select all Clipboard Copy Variable Set String %Clip% from the clipboard contents Variable Modify String %Clip%: Strip CR/LF // Delete all new lines Variable Modify String: Replace " " in %Clip% with " " // Replace double spaces for single spaces Variable Modify String %Clip%: Lowercase // Lowercase everything Variable Modify String: Replace "color" in %Clip% with "colour" // Change the spelling of words that contain "color" and "labor" Variable Modify String: Replace "labor" in %Clip% with "labour" Text Type (Simulate Keystrokes): %Clip% // Replace the selection with the revised text Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 16, 2017 Report Share Posted November 16, 2017 I too think Notepad is the best approach, given that the editing you anticipate might require manual intervention. I've no doubt Cory's probably right that using Controls would improve performance but intuitivenes usually trumps that for me! ( That's also why I haven't pursued the more compex alternative of using Run Macro in Variable .) Here's my hasty demo: // This example assumes text is on clipboard. Variable Set String %tExample% from the clipboard contents Activate or Launch: Window "Notepad", Program "notepad.exe", Parameters "" Clipboard Paste Text Box Display: Edit if necessary // Macro will also save a temporary copy of the edited text. Text Type (Simulate Keystrokes): <ALT>f // File Delay: 0.1 seconds Text Type (Simulate Keystrokes): a // Save As... Delay: 0.1 seconds Text Type (Simulate Keystrokes): C:\users\terry\TEMP-UAMike // Save As > specific temporary file Delay: 0.1 seconds Text Type (Simulate Keystrokes): <ALT>s // Save Delay: 0.1 seconds Text Type (Simulate Keystrokes): y // Say YES if asked to overwrite an existing file of this name. (No adverse effect if this is redundant.) Delay: 0.1 seconds Text Type (Simulate Keystrokes): <ALT>fx // Close Notepad. Delay: 0.1 seconds Variable Set String %tExampleEdited% from the clipboard contents // Continuing with rest of macro. Text Box Display: Edited version // Continuing with rest of macro. <COMMENT Value="This example assumes text is on clipboard."/> <VARIABLE SET STRING Option="\x02" Destination="%tExample%" NoEmbeddedVars="FALSE"/> <ACTIVATE OR LAUNCH Title="Notepad" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\Windows\\notepad.exe" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/> <CLIPBOARD PASTE/> <TEXT BOX DISPLAY Title="Edit if necessary" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n{\\colortbl ;\\red255\\green0\\blue0;}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 If necessary, edit the text now pasted into Notepad.\r\n\\par \r\n\\par Apart from Notepad's own tools, other documents, web pages, copy/pasting, coffee, etc is at your diisposal during this.\r\n\\par \r\n\\par \\cf1 Then\\cf0 close this to continue.\r\n\\par \r\n\\par (Macro will copy the text to clipboard as its next step and also save it as a temporary file.)\\f1 \r\n\\par }\r\n" Left="709" Top="578" Width="463" Height="235" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value="Macro will also save a temporary copy of the edited text."/> <TEXT TYPE Action="0" Text="<ALT>f" _COMMENT="File"/> <DELAY Flags="\x01" Time="0.1"/> <TEXT TYPE Action="0" Text="a" _COMMENT="Save As..."/> <DELAY Flags="\x01" Time="0.1"/> <COMMENT/> <TEXT TYPE Action="0" Text="C:\\users\\terry\\TEMP-UAMike" _COMMENT="Save As > specific temporary file"/> <DELAY Flags="\x01" Time="0.1"/> <COMMENT/> <TEXT TYPE Action="0" Text="<ALT>s" _COMMENT="Save"/> <DELAY Flags="\x01" Time="0.1"/> <TEXT TYPE Action="0" Text="y" _COMMENT="Say YES if asked to overwrite an existing file of this name. (No adverse effect if this is redundant.)"/> <DELAY Flags="\x01" Time="0.1"/> <TEXT TYPE Action="0" Text="<ALT>fx" _COMMENT="Close Notepad."/> <DELAY Flags="\x01" Time="0.1"/> <VARIABLE SET STRING Option="\x02" Destination="%tExampleEdited%" NoEmbeddedVars="FALSE"/> <COMMENT Value="Continuing with rest of macro."/> <TEXT BOX DISPLAY Title="Edited version" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Here is the edited text, \\b\\f1 tExampleEdited\\b0\\f0 :\r\n\\par \r\n\\par \\f1 %tExampleEdited%\r\n\\par \r\n\\par }\r\n" Left="503" Top="485" Width="1095" Height="536" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value="Continuing with rest of macro."/> Terry, East Grinstead, UK UAMikeInSituEditing.mex Quote Link to comment Share on other sites More sharing options...
Cory Posted November 16, 2017 Report Share Posted November 16, 2017 Here's a little present for you. It's a simple WinForm that is designed to be a multi-line editor that works with MEP. When you launch the program you can start typing straight away. Then when you're done, click Clip & Close button or, if your'e keyboard-centric like me, tab t hen enter. MEP can be set to wait for the program to close and grab the clipboard contents. There's a demo macro too. Just change the first line to be the path of the executable on your system. I.E. wherever you saved it. I was too lazy to get the relative path in the macro. I had a subroutine for that once, but I've lost it. TextBoxEditor.zip Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 16, 2017 Report Share Posted November 16, 2017 Interesting, thanks. I installed it and customised the path to the EXE. But on running the macro I get both the initial window and the Result. FWIW that didn't happen the very first time I ran it, when I did have an opportunity to edit the WinForm. Probably trivial but don't have opportunity to resolve it right now. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 22, 2017 Report Share Posted December 22, 2017 Well it doesn't appear that anyone is interested anyway. It's discouraging. I thought for sure UAMike would have loved this and yet I got absolutely no response. Pfft. That's what I get for doing something nice. There's nothing wrong with it. It's working perfectly. When I run the macro I get this. I edit it to add some text like this. Then I click the 'clip and close' button and I get this. I've tried it multiple times and it always works. It's too simple not to. Maybe you can show me what you mean with some screenshots. Quote Link to comment Share on other sites More sharing options...
terrypin Posted December 23, 2017 Report Share Posted December 23, 2017 OK, Cory, here's a couple of screenshots. (I assume you were replying to me?) And as you may have noticed, I too had no response from the OP in the six weeks since offering my macro. But see also my 26th November post here Quote Link to comment Share on other sites More sharing options...
UAMike Posted January 24, 2018 Author Report Share Posted January 24, 2018 On 12/22/2017 at 9:01 AM, Cory said: Well it doesn't appear that anyone is interested anyway. It's discouraging. I thought for sure UAMike would have loved this and yet I got absolutely no response. Pfft. That's what I get for doing something nice. There's nothing wrong with it. It's working perfectly. When I run the macro I get this. I edit it to add some text like this. Then I click the 'clip and close' button and I get this. I've tried it multiple times and it always works. It's too simple not to. Maybe you can show me what you mean with some screenshots. On 12/23/2017 at 4:05 AM, terrypin said: OK, Cory, here's a couple of screenshots. (I assume you were replying to me?) And as you may have noticed, I too had no response from the OP in the six weeks since offering my macro. But see also my 26th November post here My apologies! It was around this time in November that I was dealing with various family issues. It is only this week that I have returned back to work and so I actually forgot that I posed this question to begin with. I do sincerely appreciate the effort that you put forth in helping members of this community. Terry, your script is very similar to what I ended up doing with Notepad. Corey, this app looks great! I will give it a try tomorrow Quote Link to comment Share on other sites More sharing options...
Cory Posted February 15, 2018 Report Share Posted February 15, 2018 I understand family issues. I've had to make multiple trips back to Montana for deaths in the last 14 months. I'm getting jaded lately. There are tons of OPs who never respond lately that I have wasted time on and I'm getting sick of it. Having said that, it's been almost a month since you said you would "try it tomorrow". How did it go? Was the program I wrote for you useful? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.