Jump to content
Macro Express Forums

REPEAT function with variable changing... Confused...


Recommended Posts

Hello,   I'm back...

Simple / short macro

Purpose - go to multiple tabs... copy their url and store as a variable BUT the number of tabs changes each time i run the macro.

 

When I start my macro it PROMPTS for how many tabs are open and stores as integer "qtyTABS"

 

I want to go to tab, copy url and store as a string variable, refresh tab,  go to next tab and do the same action.

 

??? QUESTION is how to store as the next url variable depending on the qtyTABS variable... here is the code I have

 

REPEAT PROMPT - how many tabs do you have open - stores as "qtyTABS"

activate window 333 (window with the tabs open)

maximize current window (maximizes window with tabs open)

REPEAT START - (qtyTABS value)

  text type CTRL+L (goes to url of current window/tab and highlights)  

  text type CTRL C (copies to clipboard the url)

  variable set string URL1 from clipboard (saves url as a variable url1)

  text type F5 (refreshes page)

  text type CTRL+TAB (goes to next tab)

END REPEAT

 

Next repeat needs to store at URL2...etc

 

if I start with 5 tabs open how do I have the second repeated function store as URL2

the third repeated function store as URL3...etc

 

Thanks !!!

 

F

 

 

Link to comment
Share on other sites

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"/>

 

Link to comment
Share on other sites

Edit: Oops!  I see acantor has already replied. 

 

Do not define URL1, URL2, URL3 within the macro.

Instead, use the Variables tab of the Editor to define (add) text variable URL as an array -- a dozen entries, or however many maximum tabs you may have open. 

Use an integer variable %indx% as shown in this code sample, to store clipboard into successive entries of the array.

There is an option of Repeat Start that you could use to increment the counter (%indx%) each time through the Repeat loop, instead of using Variable Modify Integer to do it. 

The hard part is getting all the % signs in the right places when referring to elements of the array.😋

 

Variable Set Integer %indx% to 0
Repeat Start (Repeat %qtyTABS% times)

  [get the data into the clipboard]
  Variable Modify Integer %indx%: Increment
  Variable Set String %URL[%indx%]% from the clipboard contents
End Repeat

 

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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"/>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

hello,

Sorry for the delay in response... had house issues that popped up and need to be fixed...

 

YOU GUYS ARE THE BEST!!!

 

I have been playing aroudn with suggestions.

have not come to final solution YET but will let you know.

 

Thanks for all of the suggestions!!!

F

Link to comment
Share on other sites

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!

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...