function Msg(str)
  reaper.ClearConsole()
  reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

-- Get HWND
hwnd = reaper.MIDIEditor_GetActive()

-- Get current take being edited in MIDI Editor
take = reaper.MIDIEditor_GetTake(hwnd)

-- Check if take exists
if take == nil then
  Msg("Scale-finder: Whoops! No take selected.")
else

noteNames = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"}
  
  -- Count all notes in take
  retval, notes, ccs, sysex = reaper.MIDI_CountEvts(take)

  -- Setup variables for number of selected notes
  -- and an array to hold the pitch of selected notes
  selNum = 0
  selNotePitch = {}
  
  -- Loop through every note in take, and get selected notes
  -- and their pitch
  for i = 0, notes-1 do
    retval, sel, muted, startppqposOut, endppqposOut, chan, pitch, vel = reaper.MIDI_GetNote(take, i)
    
    if sel == true then
      -- Don't add note if it already exists
      note_is_dupe = false
      for n = 0, selNum-1 do
        if (selNotePitch[n] % 12) == (pitch % 12) then
          note_is_dupe = true
        end
      end
      if not note_is_dupe then -- Add note to array
        selNotePitch[selNum] = pitch % 12
        selNum = selNum + 1
      end
    end
  end
  




    -- If no notes are selected we can't generate a URL
    if (selNum == 0) then
      Msg("Scale-finder: Whoops! No notes selected.")
else
url = ""
      for i = 0, selNum-1 do
        url = url .. "" .. noteNames[selNotePitch[i] + 1] .. " "
      end
end
end
reaper.CF_SetClipboard(url)
  reaper.Main_OnCommand(40301, 0)

