If the above solution doesn’t work, then try this approach. It seems to work for Audacity (also a hardly scriptable app), by getting the file name from the Recents menu.
If the above solution doesn’t work, then try this approach. It seems to work for Audacity (also a hardly scriptable app), by getting the file name from the Recents menu.