Thanks Sselph, The first post has helped me I was able to run the script and it worked perfectly apart from the gamelist.xml doesnt appear to get updated until after exiting emulation station so it really makes that method of searching rather redundant now. I am now trying to incorporate the details from your second post how would I go about passing the $command into my script. I should be able to work out how to fix it up so that I can get the right details out of it just I haven’t got an idea where to start with this. Here’s my code so far.
from AndyPi_LCD import AndyPi_LCD
import lxml.etree as ET
root = ET.parse("./RetroPie/roms/ports/gamelist.xml")
lsp = root.findall(".//lastplayed")
mylist = [t.text for t in lsp]
newest = max(mylist)
gname = root.xpath("./game[lastplayed/text()='{}']/name/text()".format(newest))
print(gname)
namelcd = "".join(gname)
print(namelcd)
lcd=AndyPi_LCD()
lcd.lcd_init()
lcd.led(512)
lcd.static_text(1,"c","Latest Game:")
lcd.static_text(2,"c",namelcd)