Jump to content
Macro Express Forums

acantor

Members
  • Posts

    1,532
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by acantor

  1. It would be helpful to see your second script. My guess is that you need to add delays to give the windows you are interacting with sufficient time to gain focus. If you don't do this, Macro Express might move the mouse pointer to the coordinates for the "wrong" window. If this is the source of the problem, you may be able to avoid it by using Macro Express "Windows/Programs" instructions that activate windows rather than "Mouse" instructions that move the pointer and click.
  2. 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/>
  3. 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!
  4. Congratulations, Rookie Terry! I had not noticed the rankings on this forum. Is it a new system, or have I somehow managed to ignore the rankings over the past umpteen years? And why on earth are there rankings on a community forum? Is anyone out there applying for a spot in Harvard Medical School? Contributor Alan
  5. Although fixing the variable problem is do-able, my suggestion is to start the macro again from scratch. Now that you have a better sense of the "order of operations," recreating the script will likely be faster.
  6. Hi Terry, I tried again with three folders eight and nine levels deep into the folder hierarchy, as well as with the existing c drive path. It worked. Curious that the title for the c drive is different for us. Could the difference be a function of the display theme? Regional settings? Cosmic rays passing through one of our computers and randomly changing a bit?
  7. This script runs quickly. Maybe calling macros is responsible for making yours run slowly? Note that the text of the title bars of some of the instances of Windows Explorer are different than the path. I needed to insert delays between the repositioning lines. I think that's because my computer is on the slow side. You may discover that the delay statements aren't required on your computer. // Window 1 Open Folder to "C:\Users\Alan\Downloads" // Window 2 Open Folder to "C:\" // Window 3 Open Folder to "C:\Users\Alan\Pictures" // Window 4 Open Folder to "C:\Users\Alan\Saved Games" Window Reposition: Downloads Move to the top-left corner Delay: 200 milliseconds Window Reposition: c:\ Move to the top-right corner Delay: 200 milliseconds Window Reposition: Pictures Move to the bottom-left corner Delay: 200 milliseconds Window Reposition: C:\Users\Alan\Saved Games Move to the bottom-right corner <COMMENT Value="Window 1"/> <OPEN FOLDER Path="C:\\Users\\Alan\\Downloads"/> <COMMENT/> <COMMENT Value="Window 2"/> <OPEN FOLDER Path="C:\\"/> <COMMENT/> <COMMENT Value="Window 3"/> <OPEN FOLDER Path="C:\\Users\\Alan\\Pictures"/> <COMMENT/> <COMMENT Value="Window 4"/> <OPEN FOLDER Path="C:\\Users\\Alan\\Saved Games"/> <COMMENT/> <WINDOW REPOSITION Option="\x01" Title="Downloads" Partial="FALSE" Wildcards="FALSE" Method="\x02" Left="0" Top="0" Monitor="0" _IGNORE="0x0006"/> <DELAY Flags="\x02" Time="200"/> <WINDOW REPOSITION Option="\x01" Title="c:\\" Partial="FALSE" Wildcards="FALSE" Method="\x04" Left="0" Top="0" Monitor="0" _IGNORE="0x0006"/> <DELAY Flags="\x02" Time="200"/> <WINDOW REPOSITION Option="\x01" Title="Pictures" Partial="FALSE" Wildcards="FALSE" Method="\x07" Left="0" Top="0" Monitor="0" _IGNORE="0x0006"/> <DELAY Flags="\x02" Time="200"/> <WINDOW REPOSITION Option="\x01" Title="C:\\Users\\Alan\\Saved Games" Partial="FALSE" Wildcards="FALSE" Method="\x09" Left="0" Top="0" Monitor="0" _IGNORE="0x0006"/>
  8. Hi Terry, Insight Software got rid of several Macro Express instructions that may have helped accomplish what you're trying to do, possibly because Windows 10 no longer fully supports these functions. Here's a screen shot from a bygone era: When I right-click a blank area of the Windows 10 system tray, a menu appears, which has two interesting options: However, when I try these two promising-looking options, nothing happens. So the solution may be doing fancy stuff with Macro Express. It sounds do-able.
  9. I suppose this could be a Macro Express version issue. I'm using MEP 6.something. But I suspect my computer is to blame, which may be the slowest PC I've ever owned. Many window- and application-specific macros don't fire if I activate them immediately after opening a window or application. Heavens to Betsy, I've never seen such misbehaviour in a macro!
  10. I was able to prove (to myself, anyways) that the restore instruction needed time before the variable was available. I wish it wasn't so. Maybe a delay isn't necessary on a faster computer. The Windows 10 machine I bought 1.5 years ago is a bit pokey.
  11. rberq is correct. Copying these macros can lead to variable-mush. Do what he says: go to the Variable tab in all of the Ctrl+ macros and make sure there is only one text variable for each. But the scripts were still failing occasionally for me. Adding longish delays in the Alt+ macros seemed to help. Ditto for using a clipboard copy command instead of simulating Ctrl + C. I added the right arrow key to the Ctrl+ macros to make it clearer that a copy operation had occurred. Ctrl + 1: Clipboard Empty Clipboard Copy Text Type (Simulate Keystrokes): <ARROW RIGHT> Variable Set String %Clip1% from the clipboard contents Variable Save: Save Text Variables Beep: Save Text Variables <CLIPBOARD EMPTY/> <CLIPBOARD COPY/> <TEXT TYPE Action="0" Text="<ARROW RIGHT>"/> <VARIABLE SET STRING Option="\x02" Destination="%Clip1%" NoEmbeddedVars="FALSE"/> <VARIABLE SAVE Option="\x01"/> <BEEP/> Alt + 1: Variable Restore: Restore Text Variables Delay: 300 milliseconds Text Type (Simulate Keystrokes): %Clip1% <VARIABLE RESTORE Option="\x01"/> <DELAY Flags="\x02" Time="300"/> <TEXT TYPE Action="0" Text="%Clip1%"/>
  12. Hmmm. You're right. The scripts are a bit flaky... They may need delays after clipboard operations.
  13. The solution I posted reserves one variable per "clipboard": %Clip1%, %Clip2%, %Clip3%, etc. The macro that saves the variable %Clip2% doesn't do anything to %Clip1%, %Clip3%, etc. Each clipboard variable is independent of the other clipboards. The first time I tested my scripts, saving a "clipboard" did delete others. It was a bug. I inadvertently mixed up my variable names. How about sharing your code?
  14. Ctrl + 1: Clipboard Empty Text Type (Simulate Keystrokes): <CONTROL>c Variable Set String %Clip1% from the clipboard contents Variable Save: Save Text Variables Beep <CLIPBOARD EMPTY/> <TEXT TYPE Action="0" Text="<CONTROL>c"/> <VARIABLE SET STRING Option="\x02" Destination="%Clip1%" NoEmbeddedVars="FALSE"/> <VARIABLE SAVE Option="\x01"/> <BEEP/> Alt + 1: Variable Restore: Restore Text Variables Text Type (Simulate Keystrokes): %Clip1% <VARIABLE RESTORE Option="\x01"/> <TEXT TYPE Action="0" Text="%Clip1%"/> Then clone the two macros for Ctrl + 2 and Alt + 2, and so on. You'll need to rename the variable in each macro to reflect which "clipboard" it uses, e.g., %Clip2%, %Clip3%, etc.
  15. It's my favourite as well, and the most effective. I might experiment with your refinement to see if it improves things. I thought of a fourth solution this afternoon. which I thought would be the best. But when I started using it on real spreadsheets, I noted the active cell was too inconspicuous when the surrounding cells were certain colours. But it's an interesting concept: Text Type (Simulate Keystrokes): <ESC> // If a cell is being edited, exit edit mode. Text Type (Simulate Keystrokes): <CONTROL>a<CONTROL>a // Select the spreadsheet. (Must press Ctrl+A twice to capture everything) Delay: 1000 milliseconds // While spreadsheet is selected, the active cell is a different colour Text Type (Simulate Keystrokes): <ARROW RIGHT><ARROW LEFT> // Deselect
  16. Here are three solutions. The first is inspired by rberq's. Originally, my version of his script changed the Pattern Style twice: change the pattern, wait a second, and change the pattern back to its default. My "aha" moment was realizing the second half of the script was unnecessary. All I had to do was change the pattern once, and then undo. // In Excel 2019, the focus ring is harder to spot than in previous versions. // Temporarily change "Pattern Style" of the selected cells Text Type (Simulate Keystrokes): <CTRLD>1<CTRLU> // Hotkey to show "Format Cells" window Delay: 100 milliseconds // (May need a longer delay for "Format Cells" to appear) Window Resize: Format Cells Size: 0, 0 // Shrink size to zero so script is less "flashy" Text Type (Simulate Keystrokes): p // Navigate directly to the "Protection" tab, then left to the "Fill" tab Text Type (Simulate Keystrokes): <ARROW LEFT> Text Type (Simulate Keystrokes): <ALT>p // Navigate to "Pattern Style" Text Type (Simulate Keystrokes): <ARROW RIGHT><ENTER> // Choose the first pattern to the right Text Type (Simulate Keystrokes): <TAB><ENTER> // Finalize the choice Delay: 800 milliseconds // Flash the pattern for this long Text Type (Simulate Keystrokes): <CONTROL>z // Undo the above action <COMMENT Value="In Excel 2019, the focus ring is harder to spot than in previous versions."/> <COMMENT Value="Temporarily change \"Pattern Style\" of the selected cells"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CTRLD>1<CTRLU>" _COMMENT="Hotkey to show \"Format Cells\" window"/> <DELAY Flags="\x02" Time="100" _COMMENT="(May need a longer delay for \"Format Cells\" to appear)"/> <COMMENT/> <WINDOW RESIZE Option="\x01" Title="Format Cells" Partial="FALSE" Wildcards="FALSE" Method="\x00" Width="0" Height="0" _IGNORE="0x0006" _COMMENT="Shrink size to zero so script is less \"flashy\""/> <COMMENT/> <TEXT TYPE Action="0" Text="p" _COMMENT="Navigate directly to the \"Protection\" tab, then left to the \"Fill\" tab"/> <TEXT TYPE Action="0" Text="<ARROW LEFT>"/> <COMMENT/> <TEXT TYPE Action="0" Text="<ALT>p" _COMMENT="Navigate to \"Pattern Style\""/> <TEXT TYPE Action="0" Text="<ARROW RIGHT><ENTER>" _COMMENT="Choose the first pattern to the right"/> <TEXT TYPE Action="0" Text="<TAB><ENTER>" _COMMENT="Finalize the choice"/> <COMMENT/> <DELAY Flags="\x02" Time="800" _COMMENT="Flash the pattern for this long"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>z" _COMMENT="Undo the above action"/> For the second solution, you must change a setting in Control Panel > Mouse > Pointer Options. "Show location of pointer when I press the CTRL key" must be checked. The script makes a cell visible by flashing the pointer indicator three times. // In Excel 2019, the focus ring is harder to spot than in previous versions. // In "Mouse Properties" check "Show location of pointer when I press the CTRL key" // This script uses the feature to flash the mouse pointer near the focused cell. Get Mouse Position into (%x%, %y%) Relative to Current Window // Get current mouse position Mouse Move: To the Text Cursor Position Mouse Move: 30, 10 Relative to Last Position // Nudge the pointer toward the centre of the cell Text Type (Simulate Keystrokes): <CTRLD> Text Type (Simulate Keystrokes): <CTRLU> Delay: 300 milliseconds Text Type (Simulate Keystrokes): <CTRLD> Text Type (Simulate Keystrokes): <CTRLU> Delay: 300 milliseconds Text Type (Simulate Keystrokes): <CTRLD> Text Type (Simulate Keystrokes): <CTRLU> Mouse Move: %x%, %y% Relative to Current Window // Restore original mouse position <COMMENT Value="In Excel 2019, the focus ring is harder to spot than in previous versions."/> <COMMENT Value="In \"Mouse Properties\" check \"Show location of pointer when I press the CTRL key\""/> <COMMENT Value="This script uses the feature to flash the mouse pointer near the focused cell."/> <GET MOUSE POSITION Option="\x01" X="%x%" Y="%y%" _COMMENT="Get current mouse position"/> <COMMENT/> <MOUSE MOVE Option="\x00" X="0" Y="0" _PROMPT="0x000A"/> <MOUSE MOVE Option="\x03" X="30" Y="10" _PROMPT="0x000A" _COMMENT="Nudge the pointer toward the centre of the cell"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CTRLD>"/> <TEXT TYPE Action="0" Text="<CTRLU>"/> <DELAY Flags="\x02" Time="300"/> <TEXT TYPE Action="0" Text="<CTRLD>"/> <TEXT TYPE Action="0" Text="<CTRLU>"/> <DELAY Flags="\x02" Time="300"/> <TEXT TYPE Action="0" Text="<CTRLD>"/> <TEXT TYPE Action="0" Text="<CTRLU>"/> <COMMENT/> <MOUSE MOVE Option="\x02" X="%x%" Y="%y%" _PROMPT="0x000A" _COMMENT="Restore original mouse position"/> The third solution shows the current cell by selecting and deselecting the entire row, and then selecting and deselecting the entire column. The point where the two "lines" intersect is the active cell. // In Excel 2019, the focus ring is harder to spot than in previous versions. // Select the row, then select the column. The active cell is where the two "lines" meet Text Type (Simulate Keystrokes): <ESC> // If a cell is being edited, exit edit mode. Text Type (Simulate Keystrokes): <SHIFT><SPACE> // Select the entire row, pause, then deselect Delay: 900 milliseconds Text Type (Simulate Keystrokes): <ARROW RIGHT><ARROW LEFT> Text Type (Simulate Keystrokes): <CONTROL><SPACE> // Select the entire column, pause, and deselect Delay: 900 milliseconds Text Type (Simulate Keystrokes): <ARROW RIGHT><ARROW LEFT> <COMMENT Value="In Excel 2019, the focus ring is harder to spot than in previous versions."/> <COMMENT Value="Select the row, then select the column. The active cell is where the two \"lines\" meet"/> <COMMENT/> <TEXT TYPE Action="0" Text="<ESC>" _COMMENT="If a cell is being edited, exit edit mode."/> <COMMENT/> <TEXT TYPE Action="0" Text="<SHIFT><SPACE>" _COMMENT="Select the entire row, pause, then deselect"/> <DELAY Flags="\x02" Time="900"/> <TEXT TYPE Action="0" Text="<ARROW RIGHT><ARROW LEFT>"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL><SPACE>" _COMMENT="Select the entire column, pause, and deselect"/> <DELAY Flags="\x02" Time="900"/> <TEXT TYPE Action="0" Text="<ARROW RIGHT><ARROW LEFT>"/>
  17. When navigating around Excel spreadsheets without a mouse using the four arrow keys, the cell you're interacting with has a rectangle around it. This rectangle provides a visual indicator of which cell has focus. In recent versions of Excel, Microsoft has made the focus indicator fainter. As a result, when you're not using a mouse, spotting which cell you're interacting with can be challenging, especially when cells have borders around them: Note the green rectangle around cell B5. Having trouble seeing it? Exactly!!! Apparently, the faint focus indicator is hardwired into Excel, and can't be changed. Switching from Office's default visual theme helps, but not much. Although there may not be a solution to this problem unless Microsoft decides to address it, perhaps we can come up with a temporary solution: a macro that draws attention to the focused cell. The challenge: Write a Macro Express hotkey macro for Excel that helps a user spot which cell they are interacting with.
  18. Although this is not a perfect solution, this script activates each instance of File Explorer, one after another. So if you have ten windows open, and five of them are File Explorer, running the macro will place the five File Explorer windows on top of the stack. There are plenty of problems with this script: 1. The macro enumerates any window that includes "c:\" in its title bar. Therefore, the macro misidentifies all non-File Explorer windows that have "c:\" in their titles. 2. The macro misses File Explorer windows for non-c: drives, like "d:\" or "z:\". You might try to fix this by changing the target title from "c:\" to ":\" but I can imagine this might introduce all sorts of side effects. 3. The macro misses named File Explorer folders, like "This PC" and "Documents". However, I believe there is a registry hack that toggles off named folders. 4. The stop rule is ugly. If Line 5 (Window activate) fails because the window doesn't exist, the macro handles the error by bringing everything to a screeching halt. But I can live with this aesthetic blemish if others can. Hopefully someone can improve the script. Variable Set Handle %WinTitle% from all windows with the title of "C:\" Get Array Length (%WinTitle%) => %Count% Variable Set Integer %x% to 1 Repeat Start (Repeat %Count% times) Window Activate: %WinTitle[%x%]% On Error Catch Error: Window could not be found Macro Stop End Catch Error End Error Variable Modify Integer %x%: Increment End Repeat <VARIABLE SET HANDLE Option="\x00" Info="C:\\" Partial="TRUE" Wildcards="FALSE" Destination="%WinTitle%"/> <GET ARRAY LENGTH Array="%WinTitle%" Dest="%Count%"/> <VARIABLE SET INTEGER Option="\x00" Destination="%x%" Value="1"/> <REPEAT START Start="1" Step="1" Count="%Count%" Save="FALSE"/> <WINDOW ACTIVATE Title="%WinTitle[%x%]%" Exact_Match="FALSE" Wildcards="FALSE" _HANDLE="0x0006"/> <ON ERROR/> <CATCH ERROR Code="6"/> <MACRO STOP/> <END CATCH ERROR/> <END ERROR/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%x%"/> <END REPEAT/>
  19. I don't think it's possible because of how Windows works. You can only interact with one window at a time. That window is the active window. Other windows may be visible, but they are in the background. You can't interact with a non-active window until you give it focus by clicking on it or switching to it via keyboard. It may be possible to write a macro that, when activated, brings up an instance of File Explorer. Activate the macro again, and the macro brings up another instance of File Explorer, if there is one. And so on.
  20. That's similar to one of my MEP scripts that is triggered when Notepad gets focus. The macro maximizes the window. Asimov's laws notwithstanding, I think you can make a strong case that being immoral and being untruthful are justified when dealing with Captchas!
  21. Interesting problem. I don't know of a way, using only Macro Express, to test whether a window is hidden or not. And if that's the situation, there may not be a way, at least not a straightforward way, to script a macro that hides windows that are showing, and shows windows that are hidden. Consider making a feature request: add more functionality to the "If Window" dialog: Current options: If Window is Focused If Window is Running (Visible or Hidden) Requested options: If Window is Focused If Window is Running (Visible or Hidden) If Window is Running and Visible If Window is Running and Hidden
  22. In addition to Microsoft PowerToys, you can use AutoHotkey to remap keys. Both programs work nicely. The remapping process is a smidge easier with PowerToys.
  23. Invisible characters are hard to see! Invisible characters can be introduced by accident. For example, if the text you place inside the "Text Type" window was copied from another application, formatting instructions might come along for the ride. Or pressing Enter or the spacebar inside the "Text Type" window might add an extra key press that's hard to spot.
×
×
  • Create New...