tree /some/directory | print.sh
Is there any way for print.sh to know that "tree -f /some/directory" was called, without trying to parse
In general this information cannot be obtained.
print.sh can easily determine that its input is coming from a pipe, but not what is at the other end of the pipe. The first process may even have terminated, with its output fully contained in the pipe buffer. In this case, not even traversing the process list will give you any information.
Whatever it is you're trying to, you need to look for a solution in a different solution. This is probably going to involve having the script that's calling the pipe do the logging the first command.