@PTRPORT — Returns the port to which the specified printer is connected.

Syntax:
%@PTRPORT[printername]

printername: if omitted, the user’s default printer

Note that if printername is a network printer, the name @PTRPORT returns will refer to a port on the server, not a port on the local machine! The function will return ??? on any error.

echo %@ptrport["LaserJet in Office"]