Get Preview Window Path

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")
  end tell
end tell

if thefile ≠ missing value then
  urldecode(POSIX path of POSIX file thefile)
else
  error "No file has been saved!"
end if

on urldecode(theText)
  # Content omitted
end urldecode

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.

-Chris