statt =  reaper.NamedCommandLookup(40214)
reaper.MIDIEditor_LastFocused_OnCommand(statt,0)
  
item = reaper.GetSelectedMediaItem(0, 0)
if item ~= nil then
  take = reaper.GetActiveTake(item)
  if take ~= nil then
    retval, notecntOut, ccevtcntOut, textsyxevtcntOut = reaper.MIDI_CountEvts(take)
notecntOut2= notecntOut+ ccevtcntOut+ textsyxevtcntOut 
    if retval ~= nil then
      pitchOutmax = 0
inx =0
inx2=0
      for i = 1, notecntOut, 1 do
        retval, selectedOut, mutedOut, startppqposOut, endppqposOut, chanOut, pitchOut, velOut = reaper.MIDI_GetNote(take, i-1)


if        retval then
          reaper.MIDI_SetNote(take, i-1, true)
inx = inx +1
end 
      end
end
end
end

reaper.osara_outputMessage("Selected" .. inx.. "Notes" )