Jump to content
Macro Express Forums

rberq

Members
  • Posts

    1,195
  • Joined

  • Last visited

  • Days Won

    61

Posts posted by rberq

  1. Put the common (repeated) commands into a second macro, and call the second macro from the first with the "Macro Run" command.

     

    "Macro One" -
    Beginning commands set a number of variables... Be sure to "Make these variables available to macros called by this macro" (check box when defining the variables)
    Macro starts...
    ACTIVATE Window 111
    Macro Run "Macro Two"
    Activate Window 222
    Macro Run "Macro Two"
    Activate window 333
    Macro Run "Macro Two"
    End of "Macro One"


    "Macro Two" -
    command
    command
    etc, 68 commands
    etc
    End of "Macro Two"

     

     

  2. 11 hours ago, acantor said:

    If you pixel check the position of the mouse cursor, rather than its x, y coordinates, it's easier to spot the problem when the script doesn't work.

     

    Very true.  But as you say, it runs slower using the mouse.  You can have the best of both worlds by checking x,y coordinates, AND moving the mouse to those coordinates as a visual aid during debugging.  After you have found any script problems, disable the mouse movement command and just leave it in place in case you need it again later. 

    • Thanks 1
  3. In the far past I tinkered with software that was supposed to look for pictures within a screen, and tried to call them from Macro Express.  I didn't have much luck, but I wasn't too serious about it, either.  There may be fancier products available now, that you could use. 

     

    IF you can look for specific colors, and IF they are distinct from the general colors on the screen, and IF there is a limited number of screen areas where you have to look, then the macro command Get Pixel Color is useful.  For example, the code below scans vertically down the page looking for a data-entry field.  It works because I know approximately where the field will be, and field's color is different from everything around it.  But the method is too slow for scanning an entire screen, and likely will find many false positives outside of a narrow search area.

     

    // Find the type-in area by color
    Variable Set Integer %xc% to 300
    Variable Set Integer %yc% to 100
    Repeat Start (Repeat 150 times)
      Get Pixel Color at (%xc%, %yc%) Relative to Screen into %color%
      If Variable %color% Equals "4343115"
        Repeat Exit
      Else
        Variable Modify Integer: %yc% = %yc% + 8
      End If
    End Repeat
    If Variable %color% Equals "4343115"
    Else
      Macro Return
    End If
    Variable Modify Integer: %yc% = %yc% + 15
    Mouse Move: %xc%, %yc% Relative to Screen // Move mouse down a little from the top edge of the entry field
    Mouse Left Double Click

     

    • Like 1
  4. 2 hours ago, slacker said:

    (run next 3 commands then)

    if the next key pressed is "enter"

    run macro "xyz"

    else if f11 key is pressed again it restart macro "abc"

     

    Macro "abc" can do whatever, then run macro "def" (without waiting for "def" to finish), and "abc" ends.  In other words, the "IF" logic in your example will NOT exist in macro "abc". 

     

    Macro "def" issues command "Wait for Key Press", waiting for the Enter key.  When Enter is pressed, "def" runs "xyz" (again, without waiting for "xyz" to finish), and "def" ends. 

     

    So if the user presses Enter, "xyz" will be run by "def".  If the user presses f11, "abc" will run because f11 is the hotkey for "abc". 

     

    Your problem, if the user presses f11, is that macro "def" is still running, waiting for the user to (potentially) press Enter.  The easiest way out of this might be to set a short time limit on "Wait for Key Press" and end "def" without running "xyz" if Enter does not happen.  Whether a short timer will work depends on the nature of the application you are working with.  Otherwise you have to set up some kind of feedback among the macros so that "def" can be ended without running "xyz". 

  5. At Macro Express version 3, Variable Save and Variable Restore can allow a group of related macros to work with a single set of variables.  Any macro in the group has access to values previously set and/or modified by other macros in the group.  BUT -- ME version 3 allowed only one macro to run at one time.

     

    With ME versions 4/5/6, where multiple macros can run in parallel, it seems that Saves and Restores could overlap in unintended ways, so changes made by one macro would be undone by another. 

  6. I just got stuck on this same issue.  Unless “Wait for this macro to terminate before proceeding" is check-marked, the variables will NOT be available to called macros.  I suppose this makes sense, because do you want two macros, running in parallel, accessing/modifying the same variable?  Actually, you could argue this both ways – it would be a great way to coordinate activity between two parallel macros.
     
    Registry entries and Environment Variables can be used to pass data.  They are a bit clumsier to use but are not subject to the ME limitation.  Personally I stick to Environment Variables because monkeying with the Windows Registry makes me nervous.  But Environment Variables belong to Windows, and as far as I know they cannot be created on the fly from within ME (if anyone knows different please tell me).  Below are my reminder notes on Environment Variables.  I have used this method as far back as ME version 3 to pass tens-of-thousands of bytes among macros.

     

    Environment Variables in Macro Express
    To create and use one, other than the standard Windows variables:
    1. Start Macro Express from a batch file, and within the batch file define the variable; this example creates environment variable “env9999” and sets value “abc”.  (I think all environment variables are text.)
         set env9999=abc
         cd\"C:\Program Files (x86)\Macro Express Pro 6\"
         "C:\Program Files (x86)\Macro Express Pro 6\MacExp.exe"
         exit
    2. Now the environment variable can be used within ME -- can be given other values with an option of the Variable Modify String command; and the value can be retrieved with Variable Set String.  

     

    For low frequency macros, when timing is not critical, I sometimes use TXT files to pass data.  Delete any previous file if it exists, use Variable Modify String to “append to text file”.  Then in the called macro, use Text File Begin Process to read the text file and get the saved value.  It’s not an elegant method, but it works, and in practice is fast as the blink of an eye.  

     

    • Like 1
  7. Something like this should work.  It will be a learning experience to look up all these commands and enter them with the correct options. 

     

    Actually this is overkill -- you don't have to get ALL the file names to know that the folder is not empty.  As soon as one file name is returned from the Repeat with Folder command, you could "Repeat Exit" from the loop and do the typing. 
     

    //  
    Variable Set Integer %counter% to 0              // initialize counter
    Repeat with Folder c:\folder_name                // return names of all files in folder
      Variable Modify Integer %counter%: Increment   // increment counter for each file name
    End Repeat
    //  
    If Variable %counter% Is Greater Than "0"          // if folder is not empty
      Text Type (Simulate Keystrokes): <CTRLD>a<CTRLU> // type ctrl + a
      Delay: 500 milliseconds                          // delay 1/2 second
      Text Type (Simulate Keystrokes): <ENTER>         // type ENTER
    End If
    //  

     

    • Like 1
  8. 2 hours ago, Ben Lunder said:

    I was using WIND & WINU and 50ms keypresses

     

    This works for me.  Windows 10.  Notice "x" between WIND and WINU.  
    I'm sure the delays don't have to be a full one-second -- but maybe more than the 50ms you tried.  
    I don't know if Win 11 is different....    

     

    Text Type (Simulate Keystrokes): <WIND>x<WINU>
    Delay: 1000 milliseconds
    Text Type (Simulate Keystrokes): u
    Delay: 1000 milliseconds
    Text Type (Simulate Keystrokes): s

     

  9. I don't understand who is converting the language, so I'm just guessing here -- Can you paste with the mouse??? -- right click on the field, then click "Paste".

    You would have to work with the Mouse Locator tool to figure out the coordinates for moving the mouse, but if the Outlook screen is consistently the same size and location it can be done.

  10. 10 hours ago, acantor said:

    ChatGPT seems to have invented a musical collaboration between the composer and a religious scholar

     

    ChatGPT was largely trained from online text data, so probably somebody somewhere posted that collaboration theory.  I asked it to find heating thermostats with a particular feature, and it gave me three suggestions that were totally wrong -- no better than a Google search, but presented in the confident conversational tone of a used-car salesman.  Given the huge quantity of mis-information online, we should not be surprised if it leads us astray. 

    chat.JPG

  11. I had quite a conversation yesterday with ChatGPT about sorting algorithms.  It wrote me some VB code for a bubble sort, which would almost have worked.  And described several techniques for sorting large datasets, though it was kind of vague on the details.  It was apologetic and corrected its answer when I pointed out an error in its description. 

     

    Today I described to it several symptoms my car was displaying, which I had (finally) diagnosed myself.  The problem with ChatGPT was that it addressed each symptom individually, whereas only by considering all three together could you come up with the correct diagnosis.  In defense of Chat, I should add that three experienced mechanics all fell into the same trap of not putting 1 + 2 + 3 together. 

  12. Surprising.  I bet it would do well writing Visual Basic code or SQL queries -- especially SQL which is so structured. 

     

    Thank goodness I am retired so I won't be losing my job to this phenomenon.  Or maybe there will be entire new jobs opening up for those most skillful at framing questions / commands and prompting / refining ChatGPT as you have done.  Wasn't that considered a vital skill in the long-ago days when people visited oracles? 

  13. Are you are running ME on the local PC?  As I understand it, the problem is that the local PC sees only a "picture" of the application screen that physically exists on the Citrix server.  Therefore ME macros running locally do not have any "real" fields on the local screen to copy.  Is there a possibility of running ME on the Citrix server, probably in addition to running on the local PC?  Then on Citrix perhaps ME could extract fields and store them in a file accessible to the local PC via network disk or folder mapping.  Or paste the extracted data into an intermediary Notepad application on the server that is visible to the local PC.  Or maybe a (simpler} macro on the server could copy the entire screen and paste it into a file accessible to your local PC.  Then all the extraction could be done by a local macro, which presumably could type (not paste) into the application screen. 

     

    Also, aren't there Citrix options that make the clipboard usable between host and client?  Or is that what you meant when you said no text copying capabilities? 

     

    As for OCR, sorry, I have not found anything useful -- it seems that somebody must sell such a product by now.  Though ME running on the Citrix server itself might make OCR unnecessary....

    • Like 1
  14. 5 hours ago, bobaol said:

    If there is another way to store the content of the Excel Cell, then that might work.

    That's the purpose of variable %cell% -- to preserve the contents of the Excel cell so the clipboard can be used for something else. 

     

    The code you have written looks good to me.  Perhaps the Excel cell copy is failing for some reason.

    See screen image below -- try putting a Text Box Display command where the arrow points, to display what is in variable %cell%.  This should show you whether the Excel information has been captured or not. 

    ScreenCapture_2_21_2023_8_56_17.jpg

  15. If I understand you correctly, you can try this -- copy the cell content into clipboard, save clipboard in a string variable, use the string variable within the file name.

     

    Text Type (Simulate Keystrokes): <CTRLD>c<CTRLU> // copy spreadsheet cell into clipboard
    Variable Set String %cell% from the clipboard contents // save clipboard contents to string variable

     

    CLIPBOARD SAVE GRAPHIC Filename="c:\\temp2\\%Date_Time_as_text_Variable_%%cell%.jpg"

  16. 2 hours ago, vorg said:

    i understood the macro should return to the beginning of the macro when it sees  macro return on the script, apparently it doesn't, it just stops

     

    Macro Return means exit from the macro, NOT start over at the beginning of the script.  A bit confusing, yes....

     

    I like the script you listed, because it allows for the possibility that the correct color will NEVER appear.  The Repeat loop looking for color will eventually end whether it finds the color or not.  So if it ends without finding the color, you would never know -- except that the macro AGAIN double-checks the color after exiting or finishing the Repeat, and only if it ended successfully does it go on with its normal functions. 

     

    When I say the Repeat loop will "eventually" end even if the color is not found, you will have to be very patient.  One million repeats, with 1/5 second delay each time, may keep you up beyond your bedtime.  If you want it to wait 30 seconds, say, before giving up -- then change the Repeat command to 150 instead of 1,000,000.

  17. I have several macros that may run for minutes or hours without terminating.  But once I start them, I can't always remember which ones are running.  Is there anything akin to "Repeat With Windows" and "Repeat With Processes" that can list them for me?  Also, a way to selectively cancel macros?  I can hover the mouse over the running man and see/cancel them that way, but I would prefer a keyboard-based approach from within another macro.  

×
×
  • Create New...