Jump to content
Macro Express Forums

Your best Macro Express script of 2021


Recommended Posts

Describe your best (or favourite, or most useful) Macro Express script you developed, or you started using, this past year.

 

My favourite is a script I began last year, but only worked out the kinks recently. It's an application-specific script for Microsoft Outlook. The macro analyzes the body of the current email message, and decides which of about 20 folders to move the message into.

 

The script doesn't actually move messages. Instead, it does everything up to the point of moving the message. If the macro guessed right, then I confirm by pressing Enter.

 

At the core of the macro is a section of rules, e.g.:

 

If Variable %Body% Contains "Mildred"
  Variable Set String %FolderPath% to "Mildred Smith"
  Macro Return
End If
 
If Variable %Body% Contains "George"
  AND
If Variable %Body% Contains "Gratin"
  Variable Set String %FolderPath% to "George Q. Gratin"
  Macro Return
End If

etc.

 

The script navigates through the tree-view in the "Move Items" window via two strategies:

 

1. When the focus is on a collapsed item in a tree-view, pressing Keypad * instantly expands every branch.

 

2. If you type quickly into an expanded tree-view, the focus will move directly to the item you typed.

 

For example, in the "Move Items" window, you know there's a folder somewhere in the Inbox named "Mildred Smith"...

 

1. Navigate to the Inbox.

2. Press Numpad * to open every branch of the Inbox tree-view

3. Type "Mildred Smith" very quickly.

 

Focus will be on the Mildred Smith folder.

 

This macro saves me five or ten minutes per day. However, I confess that it might years to earn back the time saving, as I spent 20 or 30 hours to get the macro to work correctly and reliably!

Link to comment
Share on other sites

My most useful recently-implemented macro resulted from one of your suggestions or "challenges".  My initial reaction to your idea was, that I would rarely use it.  But once I wrote the macro, I found I very frequently used it.  The macro pops up a multiple-choice menu when using the Macro Express editor, to insert instructions into the macro being edited.  I coded it for commonly-used instructions like Delay, Set/Modify String, Set/Modify Integer, Text Type, etc.; and a few skeleton instruction groups like If/Else/Endif, and Repeat/Repeat Exit/End Repeat.  

 

My very favorite macro of all time is pretty simple, but addresses a weakness in Macro Express: the fact that Copy to Clipboard can be unreliable because it requires an unpredictable time duration to finish.  There is a ME option for Clipboard Delay that helps a little.  But often one has to put a delay into a script, following copy-to-clipboard, and hope that the delay will be sufficient.  My macro, instead, empties the clipboard, issues the Copy to Clipboard command, and then loops until the clipboard is found to be non-empty.  The ME Clipboard Delay option may be set to zero; so the copy-to-clipboard dynamically adjusts to very-fast or comparatively-slow depending on whether Windows responds very-fast or comparatively slow.  My concern, initially, was that the clipboard copy might be only partially complete -- that is, the clipboard might be non-empty but ALL the data would not yet be copied.  However, this has never been a problem.  (The macro does nothing for Clipboard Paste, which can be extremely slow.)


<COMMENT Value=" "/>
<LOG MESSAGES Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Message="Macro executed: 0_Generic_Copy_To_Clipboard" Stamp="TRUE"/>
<LOG ERRORS Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Hide_Errors="FALSE"/>
<COMMENT Value="  "/>
<COMMENT Value="Set clipboard to nulls -- check to make sure it happens"/>
<CLIPBOARD EMPTY/>
<REPEAT START Start="1" Step="1" Count="10000" Save="FALSE" Variable="%N[1]%"/>
<IF CLIPBOARD Option="\x00" CaseSensitive="FALSE"/>
<REPEAT EXIT/>
<ELSE/>
<END IF/>
<END REPEAT/>
<COMMENT Value="Copy to clipboard (CTRL-c)"/>
<CLIPBOARD COPY/>
<COMMENT Value="Loop until clipboard is non-null, that is, copy to clipboard has completed.  Since the value"/>
<COMMENT Value="to be copied may in fact BE null, we limit the loop to a nominal 1 second, then quit, leaving it null."/>
<COMMENT Value="(Due to overhead, the actual loop time will be more like 2 seconds than 1.)"/>
<REPEAT START Start="1" Step="1" Count="100" Save="TRUE" Variable="%N[99]%"/>
<DELAY Flags="\x12" Time="10"/>
<IF CLIPBOARD Option="\x00" CaseSensitive="FALSE"/>
<ELSE/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>
<COMMENT Value="Debugging and repeat-loop logging -- writes to the log the count of how many times the REPEAT loop"/>
<COMMENT Value="cycled, before the clipboard contained useful information.  Note that when trying to copy a"/>
<COMMENT Value="null field into the clipboard, the loop counter will always be the maximum.  "/>
<COMMENT Value="This logging may be commented out when you are comfortable that the macro is working properly." _ENABLED="FALSE"/>
<LOG MESSAGES Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Message="Copy-to-clipboard loop counter is %N[99]%" Stamp="TRUE" _ENABLED="FALSE"/>
<COMMENT Value="  "/>
<COMMENT Value="Return to caller"/>
<MACRO RETURN/>

 

Link to comment
Share on other sites

That macro sound very useful. I want to try it!

 

Until now, my approach has been to identify the minimum delay needed to complete clipboard operations. If a certain delay works 99% of the time, I'm good.  But it takes a lot of trial and error experimentation to zero in on a reliable value.

 

I tried modifying your script to speed up the process of determining whether the clipboard has become populated. The main change: I got rid of the delays. Looping through a repeat consumes a sliver of time even without a delay, so my thinking was that the act of looping in itself might be enough. Not sure my modification will work out in the long run.

 

I did some tests with smallish (a sentence or two), and with extremely large (millions of characters) copy operations. The number of loops when the quantity of text was small was usually one. The number of loops when copying ginormous quantities of text was 30 to 70, and took 10 or 20 seconds.

 

// Set clipboard to null -- check to make sure it happens
Clipboard Empty
Repeat Start (Repeat 1000 times)
  If Clipboard Equals ""
    Repeat Exit
  End If
End Repeat
 
// Copy to clipboard
Clipboard Copy
 
// Loop until clipboard is non-null, that is, copy to clipboard has completed.  Since the value
// to be copied may in fact BE null, we limit the loop to about 1 second, then quit, leaving it null.
// (Due to overhead, the actual loop time will be more like 2 seconds than 1.)
Repeat Start (Repeat 100 times)
  If Clipboard Does not Equal ""
    Repeat Exit
  End If
End Repeat
 
// Debugging and repeat-loop logging -- writes to the log the count of how many times the REPEAT loop
// cycled, before the clipboard contained useful information.  Note that when trying to copy a
// null field into the clipboard, the loop counter will always be the maximum.  
// This logging may be commented out when you are comfortable that the macro is working properly.
Log Messages to "C:\Temp\MacroExpressProLogFiles\MacroExpressPro_Macro_Log_File.txt"
  "Copy-to-clipboard loop counter is %Count%"
//   
// Return to caller
Macro Return

<COMMENT Value="Set clipboard to null -- check to make sure it happens"/>
<CLIPBOARD EMPTY/>
<REPEAT START Start="1" Step="1" Count="1000" Save="FALSE" Variable="%N[1]%"/>
<IF CLIPBOARD Option="\x00" CaseSensitive="FALSE"/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>
<COMMENT/>
<COMMENT Value="Copy to clipboard (CTRL-c)"/>
<CLIPBOARD COPY/>
<COMMENT/>
<COMMENT Value="Loop until clipboard is non-null, that is, copy to clipboard has completed.  Since the value"/>
<COMMENT Value="to be copied may in fact BE null, we limit the loop to about 1 second, then quit, leaving it null."/>
<COMMENT Value="(Due to overhead, the actual loop time will be more like 2 seconds than 1.)"/>
<REPEAT START Start="1" Step="1" Count="100" Save="TRUE" Variable="%Count%"/>
<IF CLIPBOARD Option="\x02" CaseSensitive="FALSE"/>
<REPEAT EXIT/>
<END IF/>
<END REPEAT/>
<COMMENT/>
<COMMENT Value="Debugging and repeat-loop logging -- writes to the log the count of how many times the REPEAT loop"/>
<COMMENT Value="cycled, before the clipboard contained useful information.  Note that when trying to copy a"/>
<COMMENT Value="null field into the clipboard, the loop counter will always be the maximum.  "/>
<COMMENT Value="This logging may be commented out when you are comfortable that the macro is working properly." _ENABLED="FALSE"/>
<LOG MESSAGES Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Message="Copy-to-clipboard loop counter is %Count%" Stamp="TRUE" _ENABLED="FALSE"/>
<COMMENT Value="  "/>
<COMMENT Value="Return to caller"/>
<MACRO RETURN/>

 

Link to comment
Share on other sites

On 12/31/2021 at 1:56 PM, acantor said:

Until now, my approach has been to identify the minimum delay needed to complete clipboard operations

 

Now I am questioning the need for my favorite macro.  I think I wrote it originally for ME 3 under Windows XP, and it did resolve all difficulties with quick vs. slow clipboard copies.  However, it appears that either ME or Windows or both are smarter now.  

 

Look at this very simple test macro, and at the log from running it.  300,000+ lines (15 MB) of text were copied to the clipboard, then pasted into Notepad.  The ME clipboard delay preference is zero.  But the results were perfect.  Though the log shows the second "abc" to be typed a few thousanths of a second after the first "abc", there was actually about six seconds that elapsed as I watched the screen.  So somewhere within ME and Windows 10 and Notepad the commands and clipboard and explicit text ("abc") are being presented in proper sequence.  (The macro also worked if I changed it to paste into Microsoft Word, but the paste time was 20 minutes!)

 

So -- conclusion -- clipboard copies and pastes seem to be coordinated by Windows, and my clipboard macro is no longer needed.  


Text Type (Simulate Keystrokes): <CTRLD>a<CTRLU>     // highlight all text
Text Type (Simulate Keystrokes): <CTRLD>c<CTRLU>     // copy to clipboard
Program Launch: "notepad" (Normal)
Parameters:                                                                            // launch Notepad
Text Type (Simulate Keystrokes): abc<ENTER>                  // type "abc"
Text Type (Simulate Keystrokes): <CTRLD>v<CTRLU>     // paste from clipboard
Text Type (Simulate Keystrokes): abc<ENTER>                 // type "abc" again
Macro Return


LOG FILE:

Saturday, January 1, 2022 1:50:12:775 PM: Macro Started (ztest)
Saturday, January 1, 2022 1:50:12:778 PM: Line 1: Text Type        ctrl-a highlight all text
Saturday, January 1, 2022 1:50:12:786 PM: Line 2: Text Type        ctrl-c copy to clipboard
Saturday, January 1, 2022 1:50:12:792 PM: Line 3: Program Launch    launch Notepad
Saturday, January 1, 2022 1:50:13:827 PM: Line 4: Text Type        type "abc"
Saturday, January 1, 2022 1:50:13:835 PM: Line 5: Text Type        ctrl-v paste from clipboard
Saturday, January 1, 2022 1:50:13:841 PM: Line 6: Text Type        type "abc" again
Saturday, January 1, 2022 1:50:13:852 PM: Line 7: Macro Return        exit macro
Saturday, January 1, 2022 1:50:13:855 PM: Macro Completed (ztest)
1/1/2022 1:50:20 PM: Macro executed: 3_Position_to_End_of_Macro_Express_Log_File  


<TEXT TYPE Action="0" Text="<CTRLD>a<CTRLU>" _COMMENT="highlight all text"/>
<TEXT TYPE Action="0" Text="<CTRLD>c<CTRLU>" _COMMENT="copy to clipboard"/>
<PROGRAM LAUNCH Path="notepad" Mode="\x00" Default_Path="TRUE" Wait="1" Get_Console="FALSE" _COMMENT="launch Notepad"/>
<TEXT TYPE Action="0" Text="abc<ENTER>" _COMMENT="type \"abc\""/>
<TEXT TYPE Action="0" Text="<CTRLD>v<CTRLU>" _COMMENT="paste"/>
<TEXT TYPE Action="0" Text="abc<ENTER>" _COMMENT="type \"abc\""/>
<MACRO RETURN/>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...