Move Data from Excel to Visual Studio?

Hello, I'm completely new to KM since I've just purchased it. I would really appreciate if you guys can help me creating a macro because I tried with IA and it didn't work. Yeah... I know.

  1. Open an Excel file (urls.xlsx).
  2. Copy each line from Column A one by one.
  3. Paste each line into Visual Studio Code’s terminal.
  4. Wait 10 seconds between pastes.
  5. Stop when all lines are done.

I honestly have been trying for almost 3 hours and at some point it worked but then it started pasting the lines from my xlsx outside the Visual Studio Code's Terminal and I had to stop.

Thank you in advance for any help and I'm sorry if this isn't the right place for that.

It would helpful if you could post your macro, that way we can see what you're working with and perhaps figure out why it might've stopped functioning as intended.

1 Like

You'll find that members of this forum are very helpful. These links will help you get started:

1 Like

I'm sorry about the delay:

tell application "Microsoft Excel"
  -- Abrir o arquivo Excel
  open "/Users/joaquim/Downloads/api/urls.xlsx"
  set planilha to active sheet of workbook "urls.xlsx"
  
  -- Pegar todas as linhas da Coluna A
  set ultimaLinha to first row index of (get end of range planilha direction toward the bottom)
  set dadosColunaA to value of range ("A1:A" & ultimaLinha) of planilha
  
  -- Fechar o Excel sem salvar
  close workbook without saving
end tell

-- Processar cada linha
repeat with linhaAtual in dadosColunaA
  set codigo to contents of linhaAtual
  
  -- Colar no terminal do VS Code
  tell application "Visual Studio Code" to activate
  delay 1 -- Esperar o VS Code abrir
  
  -- Simular teclas para colar e pressionar Enter
  tell application "System Events"
    keystroke codigo -- Cola o texto diretamente
    keystroke return -- Pressiona Enter
  end tell
  
  delay 10 -- Esperar 10 segundos entre linhas
end repeat

This is AppleScript -- do have an actual macro, or is the macro just a wrapper for this script?

If you want to troubleshoot an AppleScript, better to do so in the Script Editor application -- that way you'll see a more meaningful error message. I'm guessing it'll tell you there's an error with get end of range (Line 7) -- but even after you fix that, your code isn't setting the Clipboard for each item you want to paste.

But why use AppleScript at all? If you do want to do this with all the values in column A it's easy enough with Keyboard Maestro actions because you can do the selection with keystrokes:

Each of Column A into VS Code.kmmacros (6.2 KB)

You can add "Open a File, Folder or Application" and "Select or Show a Menu Item" actions to do the opening and closing of the Excel file too.

1 Like

Honestly, I had no idea. I'm slowly starting to discover the potential of KM and it's fascinating. Thank you for your help! It worked!