Jump to content
Macro Express Forums

acantor

Members
  • Posts

    1,531
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by acantor

  1. My script probably can't be inserted into your script. A good starting point is to simplify. My script is a basic countdown. Run my script. Observe what it does, and figure out how to works. Then modify my code, one step at a time. Or modify your code based on my code. Feel free to borrow!
  2. Here's a script that does something similar: Variable Set Integer %Counter% to 5 Text Box Display: Testing Repeat Until %Counter% Equals "0" Text Box Update: Testing Delay: 1 seconds Variable Modify Integer: %Counter% = %Counter% - 1 End Repeat Text Box Close: Testing <VARIABLE SET INTEGER Option="\x00" Destination="%Counter%" Value="5"/> <TEXT BOX DISPLAY Title="Testing" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 %Counter%\\lang1033\\f1\\fs14 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x01" Delay="0"/> <REPEAT UNTIL Variable="%Counter%" Condition="\x00" Value="0"/> <TEXT BOX UPDATE Header="Testing" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 %Counter%\\lang1033\\f1\\fs14 \r\n\\par }\r\n"/> <DELAY Flags="\x01" Time="1"/> <VARIABLE MODIFY INTEGER Option="\x01" Destination="%Counter%" Value1="%Counter%" Value2="1"/> <END REPEAT/> <TEXT BOX CLOSE Header="Testing"/>
  3. Thank you for posting your question! It's been an interesting challenge to figure out a reliable way to perform the task. I continued to experiment, and found that navigating to the Search field, and from there to the Address field, yielded better results. The reason, I believe, is that Ctrl + L (and Alt + D) cause the Address field to open like a drop-down list; and the time it takes for the list to unfurl led to timing problems. But your mileage may vary!
  4. As far as I can tell, Ctrl + L (and Alt + D) work in Firefox, Edge, Chrome, Internet Explorer, and maybe even the long-discontinued Netscape. I first learned about Alt + D during the 1990s! Ctrl + L and Alt + D appear to be identical: two different hotkeys that do exactly the same thing. The failure is intermittent in Firefox. Pressing the hotkey ALMOST always selects the entire address. But if the address ends in the forward slash, either the entire address is selected, or the final character is selected. 🤔 Adding Ctrl + A to the script was kludgy, but seemed like the easiest way to workaround the inconsistency. There may be other ways to ensure the entire address gets selected, but I haven't tried: 1. Navigate to the browser's search field, and then navigate to the Address field. Ctrl + E Shift + Tab Shift + Tab 2. Navigate to the browser's Address field, deselect the address, and reselect it: Alt + D Home Shift + End or Alt + D End Shift + Home
  5. This has been an interesting exercise. The script fails occasionally (at least in Firefox). The reason: when navigating to the address line via Ctrl + L, sometimes the entire URL is selected, and sometimes only the trailing forward slash in the URL is selected. So I added a step to select the entire address line by simulating Ctrl + A, the hotkey to select all. The script definitely needs at least one delay! Variable Restore: Restore Integer Variables Variable Set Integer %NumberOfTabs%: Prompt Text Type (Simulate Keystrokes): <CONTROL>1 // Go to first tab // Gather URLs from the Address Line Variable Set Integer %Count% to 1 Repeat Start (Repeat %NumberOfTabs% times) Text Type (Simulate Keystrokes): <CONTROL>l // Go to the Address Line Delay: 50 milliseconds Text Type (Simulate Keystrokes): <CONTROL>a // Select the URL (failsafe in case the URL isn't selected) Clipboard Copy Variable Set String %URLAddress[%Count%]% from the clipboard contents Variable Modify Integer %Count%: Increment Text Type (Simulate Keystrokes): <CONTROL><TAB> // Go to next tab End Repeat // Display the results Variable Set Integer %Count% to 1 Repeat Start (Repeat %NumberOfTabs% times) Text Box Display: Results: %Count% Variable Modify Integer %Count%: Increment End Repeat Text Type (Simulate Keystrokes): <CONTROL>1 // Return to the first tab Variable Save: Save Integer Variables <VARIABLE RESTORE Option="\x02"/> <VARIABLE SET INTEGER Option="\x01" Destination="%NumberOfTabs%" Prompt="How many tabs?" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>1" _COMMENT="Go to first tab"/> <COMMENT/> <COMMENT Value="Gather URLs from the Address Line"/> <VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/> <REPEAT START Start="1" Step="1" Count="%NumberOfTabs%" Save="FALSE"/> <TEXT TYPE Action="0" Text="<CONTROL>l" _COMMENT="Go to the Address Line"/> <DELAY Flags="\x02" Time="50"/> <TEXT TYPE Action="0" Text="<CONTROL>a" _COMMENT="Select the URL (failsafe in case the URL isn't selected)"/> <CLIPBOARD COPY/> <VARIABLE SET STRING Option="\x02" Destination="%URLAddress[%Count%]%" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/> <TEXT TYPE Action="0" Text="<CONTROL><TAB>" _COMMENT="Go to next tab"/> <END REPEAT/> <COMMENT/> <COMMENT Value="Display the results"/> <VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/> <REPEAT START Start="1" Step="1" Count="%NumberOfTabs%" Save="FALSE"/> <TEXT BOX DISPLAY Title="Results: %Count%" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs40 %URLAddress[%Count%]%\\fs20 \r\n\\par }\r\n" Left="821" Top="Center" Width="714" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/> <END REPEAT/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>1" _COMMENT="Return to the first tab"/> <VARIABLE SAVE Option="\x02"/>
  6. We've confirmed that using an array is a good way to tackle this puzzle!
  7. A small refinement: Add this as the first line of the script: Variable Restore: Restore Integer Variables And make this the last line of the script: Variable Save: Save Integer Variables This change causes the value of %NumberOfTabs% to be preserved between runs. When running the script repeatedly, the script will make the last value the default. You won't need to type the same value each time. Could be handy if you're always checking the same number of tabs. (The value won't survive a reboot.)
  8. You can use an array to capture the URLs. I defined a text variable %URLAddress[%Count%]% with space for up to 100 URLs. %URLAddress[1]% %URLAddress[2]% %URLAddress[3]% etc. If the script occasionally skips a URL, you may need to insert strategic delays. Variable Set Integer %NumberOfTabs%: Prompt Text Type (Simulate Keystrokes): <CONTROL>1 // Go to first tab Variable Set Integer %Count% to 1 Repeat Start (Repeat %NumberOfTabs% times) Text Type (Simulate Keystrokes): <CONTROL>l // Select the URL Clipboard Copy Variable Set String %URLAddress[%Count%]% from the clipboard contents Variable Modify Integer %Count%: Increment Text Type (Simulate Keystrokes): <CONTROL><TAB> // Go to next tab End Repeat // Display the results Variable Set Integer %Count% to 1 Repeat Start (Repeat %NumberOfTabs% times) Text Box Display: Results: %Count% Variable Modify Integer %Count%: Increment End Repeat Text Type (Simulate Keystrokes): <CONTROL>1 // Return to the first tab <VARIABLE SET INTEGER Option="\x01" Destination="%NumberOfTabs%" Prompt="How many tabs?" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0"/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>1" _COMMENT="Go to first tab"/> <COMMENT/> <VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/> <REPEAT START Start="1" Step="1" Count="%NumberOfTabs%" Save="FALSE"/> <TEXT TYPE Action="0" Text="<CONTROL>l" _COMMENT="Select the URL"/> <CLIPBOARD COPY/> <VARIABLE SET STRING Option="\x02" Destination="%URLAddress[%Count%]%" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/> <TEXT TYPE Action="0" Text="<CONTROL><TAB>" _COMMENT="Go to next tab"/> <END REPEAT/> <COMMENT/> <COMMENT Value="Display the results"/> <VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/> <REPEAT START Start="1" Step="1" Count="%NumberOfTabs%" Save="FALSE"/> <TEXT BOX DISPLAY Title="Results: %Count%" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs40 %URLAddress[%Count%]%\\fs20 \r\n\\par }\r\n" Left="821" Top="Center" Width="714" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/> <END REPEAT/> <COMMENT/> <TEXT TYPE Action="0" Text="<CONTROL>1" _COMMENT="Return to the first tab"/>
  9. Let's say you have a macro called "Test" that consists of three instructions: Macro Run: Test1 Macro Run: Test2 Macro Run: Test3 When you trigger "Test," Test1 will run. Then Test2. And finally, Test3. However, if Test1, Test2, or Test3 contains this instruction: Macro Stop Then Test will stop at the point the instruction is encountered. For example, here are three macros: Test1: Text Box Display: This is Test1 --------------- Test2: Text Box Display: This is Test2 Macro Stop --------------- Test3: Text Box Display: This is Test3 If you run Test, you'll see the first Text Box, the second Text Box, but not the third.
  10. This thread includes a description of another way to navigate to a location on a web page. Like Cory's method, knowing how to get around a web page via the keyboard is extremely helpful.
  11. I don't think there's an easier way. When you are manually setting up the macro, you should be able to use Ctrl + space to automate the process of setting the coordinates. Variable Set String %SoundFile1% to "c:\tmp\Sounds\Beep.wav" Sound File: %SoundFile1%
  12. Rberq's example may be the most elegant way, using Macro Express, to "hunt" for a pixel colour. But because pixel checking is handled mathematically, the approach can be challenging to debug if the script fails. 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. This pixel hunting method runs noticeably slower than Rberq's method. Mouse Move: 800, 240 Relative to Current Window Repeat Start (Repeat 20 times) Get Pixel Color from Beneath the Mouse into %PixelColour% Delay: 50 milliseconds If Variable %PixelColour% Equals "14120960" Mouse Left Click Repeat Exit End If Mouse Move: 0, 50 Relative to Last Position End Repeat I've written a few scripts that calculate the starting coordinates, or the x or the y coordinate, based on the size of the window. For example, if I know the target I'm aiming for lies along a horizontal line half way across the window, I might do this: // Half the width of a window is the x position Variable Set Integer %Width%: Set to the Current Window's Width Variable Modify Integer: %x% = %Width% / 2 // Start hunt at the top of the window Variable Set Integer %y% to 0 Repeat Start (Repeat 20 times) Mouse Move: %x%, %y% Relative to Current Window Get Pixel Color from Beneath the Mouse into %PixelColour% Delay: 50 milliseconds If Variable %PixelColour% Equals "14120960" Mouse Left Click Repeat Exit End If Variable Modify Integer: %y% = %y% + 20 End Repeat
  13. Rather than looking for images and clicking on them, I think it will be easier to automate tasks in Teams by sending sequences of keystrokes. Many key sequences in Teams are standard; they work in almost all well-behaved applications. Other key sequences in Teams are truly bizarre, and hard to figure out. (For example, the only way to perform one task via keyboard is to press a key combination Microsoft stopped supporting around the time of Windows ME.) Perhaps Microsoft has documented ways to interact with Teams via keyboard / no mouse. You could start there. My recollection is that the set of keys for performing most tasks in Team include: F6 Ctrl + 1, Ctrl + 2, etc. The four arrow keys Tab and Shift + Tab spacebar Enter Once you figure out the key sequence, you can do things like this in Macro Express. (Note that this is for illustration purposes only. The sequence won't do anything useful in Teams.) Text Type (Simulate Keystrokes): <CONTROL>2 Text Type (Simulate Keystrokes): <TAB><TAB><TAB><TAB> Text Type (Simulate Keystrokes): <ARROW DOWN><ARROW DOWN><ARROW DOWN> Text Type (Simulate Keystrokes): <ENTER>
  14. I started reading Cory's explanation about local and global variables, and realized my understanding of how variables get passed from one macro to another might be incorrect. So I created simplified versions of 1Testing and 2Testing that DON'T save and restore the variables: 1Testing Variable Set Integer %CurrentSecond%: Set to the Current Second Macro Run: 2Testing <VARIABLE SET INTEGER Option="\x15" Destination="%CurrentSecond%"/> <MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/> 2Testing MessageBox: Status <MESSAGEBOX Caption="Status" Message="Current second is %CurrentSecond%" Icon="2"/> To my surprise, the simplified macros work! Thank you Cory for taking the time to write that description!
  15. Create two macros: Macro nickname: 1Testing Activation: A hotkey you can easily remember, e.g., the Insert key, Ctrl+T, or whatever. Variable Restore: Restore All Variables Variable Set Integer %CurrentSecond%: Set to the Current Second Variable Save: Save All Variables Macro Run: 2Testing <VARIABLE RESTORE Option="\x00"/> <VARIABLE SET INTEGER Option="\x15" Destination="%CurrentSecond%"/> <VARIABLE SAVE Option="\x00"/> <MACRO RUN Use_ID="FALSE" Name="2Testing" ID="-1" Wait="TRUE"/> Macro nickname: 2Testing Activation: None. Variable Restore: Restore All Variables MessageBox: Status <VARIABLE RESTORE Option="\x00"/> <MESSAGEBOX Caption="Status" Message="Current second is %CurrentSecond%" Icon="2"/> The first macro generates a value based on the current second. The value is stored in an integer variable called %CurrentSecond%. The second macro, which is called by the first macro, outputs the value of %CurrentSecond% in a message box. When I press the hotkey to activate the first macro, the script assigns a value to %CurrentSecond%. The value is passed on to the second macro, which displays the value. To confirm the value is getting passed from the first to the second macro, repeat.
  16. You probably don't need to use the clipboard to output the filename into the field. If the cursor is in already in the field, do this: Text Type (Simulate Keystrokes): %FileName% If the field doesn't have focus, you will have to start by giving it focus. For example, in the "Save As" dialog boxes in many applications, Alt+N is the hotkey to navigate to the "File name" field: Text Type (Simulate Keystrokes): <ALT>n Text Type (Simulate Keystrokes): %FileName% But you must transfer the value of %FileName% to the clipboard, do this: Clipboard Start Copy Text Type (Simulate Keystrokes): %FileName% Clipboard End Copy
  17. Actually, Cory, your method works nicely. This is slightly convoluted: the script "flips a coin" and 50% of the time, changes an uppercase letter to a lowercase letter. I didn't try to include numbers or symbols (like hyphen and underscore) into the file name. But if that's what's wanted, I'm sure it can be done. Variable Set String %FileName% to "" Repeat Start (Repeat 10 times) Variable Set Integer %x% to a random value between 65 and 90 // Pick an ASCII number between A and Z (65 - 90) Variable Set Integer %CoinFlip% to a random value between 1 and 2 // Flip a coin. 50% of time, compute the lowercase value If Variable %CoinFlip% Equals "1" Variable Modify Integer: %x% = %x% + 32 End If Variable Set to ASCII Char %x% to %Char% Variable Set String %FileName% to "%FileName%%Char%" End Repeat Text Box Display: File Name <VARIABLE SET STRING Option="\x00" Destination="%FileName%" NoEmbeddedVars="FALSE"/> <COMMENT/> <REPEAT START Start="1" Step="1" Count="10" Save="FALSE"/> <VARIABLE SET INTEGER Option="\x05" Destination="%x%" Minimum="65" Maximum="90" _COMMENT="Pick an ASCII number between A and Z (65 - 90)"/> <VARIABLE SET INTEGER Option="\x05" Destination="%CoinFlip%" Minimum="1" Maximum="2" _COMMENT="Flip a coin. 50% of time, compute the lowercase value"/> <IF VARIABLE Variable="%CoinFlip%" Condition="\x00" Value="1" IgnoreCase="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%x%" Value1="%x%" Value2="32"/> <END IF/> <VARIABLE SET TO ASCII CHAR Value="%x%" Destination="%Char%"/> <VARIABLE SET STRING Option="\x00" Destination="%FileName%" Value="%FileName%%Char%" NoEmbeddedVars="FALSE"/> <END REPEAT/> <COMMENT/> <TEXT BOX DISPLAY Title="File Name" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 %FileName%\\lang1033\\f1\\fs14 \r\n\\par }\r\n" Left="821" Top="432" Width="530" Height="249" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
  18. Here's a way to generate a random ten-character string. The macro randomly picks characters from a list of 65: [A-Z] [a-z] [0-9] and the hyphen [-] and underscore [_]. Variable Set String %FileName% to "" // File name to build Variable Set Integer %NumberOfCharacters% to 10 // Number of characters for the file name // A list of every legal character for the file name. I've chosen 65 characters Variable Set String %LegalCharacters% to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890-_" Repeat Start (Repeat %NumberOfCharacters% times) Variable Set Integer %RandomValue% to a random value between 1 and 65 Variable Modify String: Copy part of text in %LegalCharacters% starting at %RandomValue% and 1 characters long to %Character% Variable Modify String %FileName%: Append Text (%Character%) // Build file name End Repeat Text Box Display: Ten character file name <VARIABLE SET STRING Option="\x00" Destination="%FileName%" NoEmbeddedVars="FALSE" _COMMENT="File name to build"/> <VARIABLE SET INTEGER Option="\x00" Destination="%NumberOfCharacters%" Value="10" _COMMENT="Number of characters for the file name"/> <COMMENT Value="A list of every legal character for the file name. I've chosen 65 characters"/> <VARIABLE SET STRING Option="\x00" Destination="%LegalCharacters%" Value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890-_" NoEmbeddedVars="FALSE"/> <COMMENT/> <REPEAT START Start="1" Step="1" Count="%NumberOfCharacters%" Save="FALSE"/> <VARIABLE SET INTEGER Option="\x05" Destination="%RandomValue%" Minimum="1" Maximum="65"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%Character%" Variable="%LegalCharacters%" Start="%RandomValue%" Count="1" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%FileName%" Value="%Character%" NoEmbeddedVars="FALSE" _COMMENT="Build file name"/> <END REPEAT/> <COMMENT/> <TEXT BOX DISPLAY Title="Ten character file name" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs40 \r\n\\par %FileName%\\lang1033 \r\n\\par }\r\n" Left="821" Top="432" Width="341" Height="266" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
  19. Instead of modifying an existing macro, try creating a new one, with WhatsApp.exe as the scope (and nothing else). For testing purposes, I suggest disabling all macros that involve WhatsApp. If you can't get it to work, try changing the scope to window specific. You may need to choose a partial match. Still no luck? Try making the macro Global. Still nothing? It might not be do-able with Macro Express.
  20. Not sure this is the best way to handle this. A macro that runs in the background waiting for something to happen is, in my experience, prone to failure because it interferes with, or prevents, other macros from running. Perhaps this needs to be a sequence of two (or more) scripts instead of one. What's good about your macro is that you've automated the opening of the Text Type dialog, and that's not easy! Kudos!
  21. Tonight I typed this into ChatGPT: Write a rhyming poem about macro writing Then I asked ChatGPT to regenerate the response. The new poem might be a smidge better! Or is it just the same doggerel in a slightly different form??
  22. When I'm using applications that automatically convert a URL that is typed into a hypertext link, a macro that inserts the same URL also is converted to a hypertext link.
  23. I tried triggering a hotkey macro in the Windows 10 task manager, and nothing happened. It looks like certain system windows block Macro Express, although not all system windows. At least in Windows 10. For example, I can trigger a Macro Express script when this window has focus:
  24. Drag the red and blue Macro Express icon from the notification area to the System Tray. Then you will always know when Macro Express is running. On my system, the running green man appears on the left edge of the System Tray. Notice the Macro Express icon three icons to the right.
×
×
  • Create New...