title: What is wrong with my AppleScript code? Pulling URL from search
body: <p>I have a list of lots of UPCs where I need to search for the UPC on Amazon, and then return the URL of the first product that pops up. I am trying to write an AppleScript to do this quickly, where I can just change the number of iterations based on how many UPCs I have to search. </p>
  
  <p>All the search links for the UPCs are in an Excel file in column A (e.g. <a href="https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dtoys-and-games&amp;field-keywords=889698110563" rel="nofollow noreferrer">https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dtoys-and-games&amp;field-keywords=889698110563</a>). Column B is blank to put the intended link for the result.</p>
  
  <p>Below is what I have written, and it's not working. Please help me troubleshoot! </p>
  
  <pre><code>repeat 5 times
      activate application "Microsoft Excel"
      tell application "System Events" to tell process "Microsoft Excel"
          keystroke "c" using command down
          key code 124
      end tell
  
      tell application "System Events" to tell process "Google Chrome"
          keystroke "l" using command down
          keystroke "v" using command down
          key code 36
      end tell
  
      tell application "System Events" to tell process "Google Chrome"
          set frontmost to true
          repeat 39 times
              keystroke tab
          end repeat
          key code 36
      end tell
  
      tell application "Google Chrome"
          set the clipboard to (URL of active tab of first window as text)
      end tell
  
      tell application "System Events" to tell process "Microsoft Excel"
          keystroke "v" using command down
          key code 125
          key code 123
      end tell
  end repeat
  </code></pre>