Jump to content
Macro Express Forums

acantor

Members
  • Posts

    1,532
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by acantor

  1. Thank you Terry and Cory for mulling this with me. My solution of drilling through the UI is not particularly elegant, but it does get the job done. My macro is designed to automate the process of preparing an email message in Outlook that includes a certain attachment. My first attempt was to use Macro Express to manipulate the UI of Outlook to select the attachment. The macro worked, but sometimes misfired. My second attempt is the subject of this thread: Copy the file in Windows Explorer, and paste it directly into an Outlook message. (Not many people realize this, but a file copied to the clipboard and pasted directly into an Outlook message becomes an attachment.) Attempt 2 works faster and is more reliable than Attempt 1, but it's not pretty. Cory's message has given me an idea that I will eventually try: use Outlook VBA.
  2. Does anyone know a way to programmatically copy a file, via Macro Express, without navigating through the Windows user interface? For example, let's say there is a file on my hard drive that I frequently need to copy to the clipboard: c:\users\docs\tips.pdf I don't want to do this, which works, but is occasionally unreliable: Open Folder to "c:\users\docs" // Open the folder that contains the file Delay: 500 milliseconds Text Type (Simulate Keystrokes): tips // Navigate to a file that starts with "tips" via the incremental search built into a folder Delay: 200 milliseconds Clipboard Copy Delay: 400 milliseconds Window Close: c:\users\docs // Close the folder that contains the file In other words, is there a programmatically way to copy a file to the clipboard with MEP? I think there is a way to do it with files that contain graphics, but not for doc files, pdfs, etc.
  3. Try selecting text with the keyboard instead of the mouse. This may be easier if you press F7 in the browser to enter cursor mode.
  4. Macro Express can detect controls in some programs, but not in browsers. However, there are ways to navigate to controls via Macro Express without clicking on x, y coordinates. One approach is to search for unique text near the target, and then either Tab or Shift Tab to the desired control. In pseudo code: Type {Control}f ' Find on the page. In some (most?) browsers, F3 does the same thing. Delay 100 ms Type Surname: Type {Enter} Delay 100 ms Type {Escape} ' Cancel the search Delay 100 ms Type {Tab}{Tab} ' Tab to the desired field or control You will need to play with delays and target text to get this to work reliably.
  5. Try Win + D instead of Win + M. Both hotkeys do roughly the same thing.
  6. What you are trying to do can be made to work, although you may find you need a longer delay after switching to a new window. As for populating the variables with window titles, Macro Express is fast enough to do it on the fly. Handle variables might be a better way, as handles differentiate windows with identical titles.
  7. Hi Terry, Move to Text Cursor Position does not work for me in Internet Explorer (Version 11). I tried it two ways: with caret browsing on and off. In both cases, the mouse cursor jumped to the upper left corner of the viewport. Could there be an MSIE setting that controls this behaviour? There are situations when mouse emulation is crucial, although the OP has not described the task in enough detail to determine whether it is the best course of action.
  8. When text is selected in an Internet Explorer or Firefox window, there is no straightforward way to ascertain the x and y coordinates of the selection. You might think this would help: Mouse Move: To the Text Cursor Position But it does not. In browsers, the position of selected text is NOT the same as the position of the text cursor. Instead, the text cursor is in the upper-left corner of the viewport. The only way I know with MEP to get the coordinates of a selection on a web page is to hunt for pixel colours. I doubt it's possible to make these scripts 100% reliable. I have developed many such scripts; they take time and effort to work right. Usually tradeoffs are needed. For example, an MEP script to check every pixel on a screen may take several minutes to execute. To force these scripts to run acceptably fast, you might decide to choose to check a single vertical or horizontal line, a small region of the screen, or every five (or ten or hundred) pixels instead of every pixel. Or you might decide to manually move the mouse cursor nearby. Here is an example of a MEP script that searches the 400 x 400 pixel region in the upper-left corner of a window: // Search a 400 pixel by 400 pixel rectangular region for a colour // Start at the top-left. Move right along a horizontal line, testing each pixel. At end of row, go to start of next line, and try again. // Specify pixel colour to search for. Use "Mouse Locator" to obtain value. Variable Set Integer %PixelTarget% to 7004146 // This colour appears in the ME Pro Script Editor, in the "M" icon to the left of "Macro Nickname:" // Specify (x, y) of the top-left corner of the search rectangle... Variable Set Integer %xStart% to 0 Variable Set Integer %yStart% to 0 // Specify (x, y) of the bottom-right corner of search rectangle... Variable Set Integer %xEnd% to 400 Variable Set Integer %yEnd% to 400 // Calculate length and height of search rectangle: Variable Modify Integer: %xLength% = %xEnd% - %xStart% Variable Modify Integer: %yHeight% = %yEnd% - %yStart% // Set coordinate to test. (Start in upper-left corner)... Variable Set Integer %xCurrent% to %xStart% Variable Set Integer %yCurrent% to %yStart% // Start with the first "row" of pixels. We test up to yHeight rows... Repeat Start (Repeat %yHeight% times) // Test each pixel along a horizontal line xLength pixels long... Repeat Start (Repeat %xLength% times) Get Pixel Color at (%xCurrent%, %yCurrent%) Relative to Current Window into %PixelColour% If Variable %PixelColour% Does not Equal "%PixelTarget%" // Increment x so we test next pixel to the right... Variable Modify Integer %xCurrent%: Increment Else // Pixel found... Mouse Move: %xCurrent%, %yCurrent% Relative to Current Window Text Box Display: Found! Macro Stop End If // Continue until the entire row is tested... End Repeat // Reset x to its original value, and increment y so we can test pixels in the next row... Variable Set Integer %xCurrent% to %xStart% Variable Modify Integer %yCurrent%: Increment End Repeat // Pixel not found... Mouse Move: %xEnd%, %yEnd% Relative to Current Window Text Box Display: Not Found! In theory, the script above can identify the upper-left coordinates of a selection, provided you identify its colour in advance, and assuming the selection appears within the specified 400 x 400 pixel region. To do this, the script loops up to 160,000 times. On my i7 computer, this takes over 40 seconds. So my script may not practical. Perhaps others can suggest more efficient brute-force techniques.
  9. Thank you for the new release. I will take it through its paces!
  10. But now I see a problem. Without the ability to convert a handle variable to a string or integer variable, there is no way to check whether there are two windows or one. You cannot rely on window titles, as it's possible to open several windows with identical titles. Here is an example, partially in pseudo code... // Click somewhere.... Wait for Left Mouse Click // Get title and handle for the current window [1] Variable Set String %WindowTitle1% to topmost window title Variable Set Handle %WindowHandle1% from a window with the title, "%WindowTitle1%" // Click somewhere else... Wait for Left Mouse Click // Get title and handle for the current window [2] Variable Set String %WindowTitle2% to topmost window title Variable Set Handle %WindowHandle2% from a window with the title, "%WindowTitle2%" // Did the two clicks occur in the same window, or in different windows? // Note, pseudo code follows, because testing Handle variables, or converting them to strings or integers, is not (yet) supported... If %WindowHandle1% = %WindowHandle2% // Clicks were in the same window Else // Clicks were in two different window End If // Alternatively.... Convert %WindowHandle1% to Integer Variable %WindowHandle1Integer% Convert %WindowHandle2% to Integer Variable %WindowHandle2Integer% If %WindowHandle1Integer% Equals %WindowHandle2Integer% // Clicks were in the same window Else // Clicks were in two different window End If
  11. Hi Terry, I tried to replicate the problem, but couldn't. When I disabled the line that calls the sub macro, MEP ignores it.
  12. Cory, I think you are on to something. Here are the results when I ran the script with the "Variables" window open. The value of %WindowHandle% displayed as "1181220" not "Document - WordPad." I closed WordPad, opened it, and ran the macro again.The value of %WindowHandle% was completely different. It would appear that MEP does not provide a way to manipulate Handle variables. But the Handles are there, working in the background. There probably is no way to convert them to String or Integer variables. Thanks for the good lead, Cory. I understand Handle variables much better now. Alan
  13. I am trying to use Handle variables to positively identify a window when there are two (or more) windows with the same title. This test script does the following 1. Sets a handle variable based on the current window title 2. Activates Microsoft Word. 3. Types some text. 4. Activates the original window (from Step 1.) 5. Types out the title and handle. // Get title and handle for the current window. There may be two or three windows with exactly the same title Variable Set String %WindowTitle% to topmost window title Variable Set Handle %WindowHandle% from a window with the title, "%WindowTitle%" // Jump to a different window, and do something, e.g., type into Microsoft Word Window Activate: Microsoft Word Delay: 500 milliseconds Text Type (Simulate Keystrokes): This is Microsoft Word Delay: 500 milliseconds // Activate the original window, and output the title and handle Window Activate: %WindowHandle% Delay: 500 milliseconds Text Type (Simulate Keystrokes): This is the original window. Title = %WindowTitle% Handle = %WindowHandle% It seems to work, but I am not understanding something. Assuming the original window is an unsaved Notepad document, this is what the final text type command outputs: This is the original window. Title = Untitled - Notepad Handle = Untitled - Notepad Huh? Why is %WindowTitle% the same as %WindowHandle%? My understanding is that each window has a unique handle. Therefore, I expect the value of %WindowHandle% to be different than %WindowTitle%. If there are two windows titled "Untitled - Notepad," how can MEP determine which one I want if the value of the handle variable has the same value as the window title? Maybe I am displaying handle variable values in the wrong way. If this is the case, how do I monitor the true values of handle variables?
  14. What method are you using to open a new tab? The fastest way is probably text type Ctrl + T
  15. One of my scripts copies information to the clipboard, then copies the clipboard to a text variable for further processing. After several manipulations, I need to know the number of commas in the text variable. Is there a straightforward way to do this in MEP? I found a solution, but there must be a simpler way! See below. My approach involves 45 or 50 lines of code that incrementally replace every character, except commas, with nothing. I am left with a text variable that consists only of commas, so I get the answer by asking for the length of the string variable: Variable Modify String: Replace "a" in %Text% with "" Variable Modify String: Replace "b" in %Text% with "" Variable Modify String: Replace "c" in %Text% with "" etc. Variable Modify String: Replace "1" in %Text% with "" Variable Modify String: Replace "2" in %Text% with "" Variable Modify String: Replace "3" in %Text% with "" etc. Variable Modify String: Replace "-" in %Text% with "" Variable Modify String: Replace "." in %Text% with "" Variable Modify String: Replace "(" in %Text% with "" etc. Variable Set Integer %NumberOfCommas% to the length of variable %Text%
  16. The Application key is one of the few keys that cannot be assigned via Macro Express. Tab is another. There are a handful of others. But with so many possible key combinations, I have not found these lacks to be a major issue. I recently noticed that it's possible to trigger a macro by "pressing" the middle mouse button. A macro triggered by clicking the mouse runs counter to many people's expectations.
  17. There is a downside. If a script gets "stuck" during a timed delay, it may be impossible to break out of it -- except by rebooting the computer. During one macro scripting project, I was forced to switch all timed delays into delays because my computer was hanging several times an hour. I try to avoid delays of any kind -- if I can get away with it.
  18. You don't need to use a repeat. Use "schedule" as the activation:
  19. Cory, thank you for your code! It is, in many respects, similar to what I did: I assigned a line to a text variable, found its length, and used a repeat to build a variable, character by character, inserting a space after each. I was hoping there might be a string or array manipulating function that would "deconstruct" a variable into characters plus spaces, without the need to loop. But my guess is that MEP does not include this capability. I outputted each line after it was processed, but MEP froze after processing a few hundred lines. I fixed this by slowing the keystroke rate. But I like your approach of storing everything in a variable. I am going to try it. Any idea of the maximum length of a text variable that MEP can handle? (After performing all the operations on the file, the result consisted of close to 90,000 characters.)
  20. Text Type (Simulate Keystrokes): <SHIFT><ENTER> The above should work without involving the clipboard.
  21. I have a text file that consists of almost 10,000 lines of text like this: A AB BA CDA DRQ I need to transform the file into this format: A\A AB\A B BA\B A CDA\C D A DRQ\D R Q The approach I took was to use the MEP ASCII File Process command. To begin, I transformed the file into a tab deliminated file by adding a tab to the end of each line. (Easy to do with search and replace.) After trial and error experimentation, the macro worked. It copies each line to a variable, appends a backslash, and adds a space after each letter. I am curious to know how other people might add a space after each letter. My code is more convoluted than I expected. Although it was a fun exercise, I now want to learn more elegant ways to accomplish the same thing.
  22. Sometimes it is most reliable to find text nearby the target, and then either Tab or Shift+Tab to the target. In this example, the target is three tabs before the "Country" field. You might want to do this if the text associated with the target itself is not searchable (e.g., an image) or is ambiguous (e.g., there is more than one field with exactly the same label.) // Navigate to a button that is three controls "before" the Country field // Text Type: <CONTROL>f // Initiate search Delay: 100 ms // Text Type: Country // We will search for the "Country" field... Delay: 100 ms // Text Type: <ENTER> // Do the search Delay: 100 ms // Text Type: <ESC> // Cancel search, which gives focus to the found text Delay: 100 ms // Text Type: <SHIFT><TAB><SHIFT><TAB><SHIFT><TAB> // Back-tab three times... Delay: 100 ms // Text Type: <ENTER> // We arrive at the button. Activate it.
  23. If you are able to reach the target by searching for a word, pressing Esc, pressing Tab (which moves focus to the next element), then Shift + Tab (which moves focus back to the target), and then Enter.... you have found a solution. It's not elegant, but it's a solution nonetheless.
  24. Try spacebar instead of Enter. Buttons generated via JavaScript may not be keyboard accessible. Ditto for HTML buttons that are improperly coded. Have you validated the code? A valid HTML button that has keyboard focus is activated by pressing Enter. If this doesn't work, fix the code on your website.
×
×
  • Create New...