That looks like something I wrote long ago and scarfed the vanilla decode routine from here, but I won't swear up and down.
You can make it generic to the front application easily enough:
tell application (get path to frontmost application as text) to set frontApp to its name
tell application "System Events"
tell process frontApp
set thefile to value of attribute "AXDocument" of (first window whose subrole is "AXStandardWindow")
if thefile ≠ missing value then
urldecode(POSIX path of POSIX file thefile)
error "No file has been saved!"
# Content omitted
More recently I'd shell out to Perl, Python, or Ruby to do the decode, but at this point it makes more sense to use JXA.