Shorten the `system.perspective.print` function call

I use system.perspective.print a ton, especially in an involved script. On a previous keyboard I had, I had a hotkey mapping to where I'd press two keys simultaneously and it'd insert system.perspective.print(" for me, which was nice.

I decided to try to shorten this call so it would save me a few character types - whether it accomplishes this or not, you be the judge....

Step 1: Create a new script called sp (or whatever you'd like to call it)

Go to the Scripting section of the designer, right-click and add a new script - I called mine sp.

Step 2: Add script

image

def pr(msg, self):
	pageId = self.page.id
	sessionId = self.session.props.id
	
	system.perspective.print(msg, pageId=pageId, sessionId=sessionId)

The reason why I didn't just use print is because I got a syntax error and I figured it wouldn't be worth digging into it.

EDIT - STEP NOT NEEDED (thanks pturmel!) Step 3: Import sp into your onActionPerformed script, for example

image

#import sp

Step 4: Sit back and relax

Now, instead of typing

system.perspective.print("you got past that tricky bit haha have a coffee break")

you can just do

sp.pr("please support me on pateron for more time saving perspective tips", self)

This saves you from typing 13 characters in each print statement, which, if your script is anything like mine and you use system.perspective.print about 350 times per script, is a whopping 4,550 characters.

You're welcome.

image

Other combinations of script/function names:

  • p.rint()
  • pri.nt()
  • prin.t()
  • printThisMessageForMePleaseAndThankYou()
2 Likes

You should not be importing any project script. Just use it.

1 Like

:thinking:

It's a bit of a hack, but I wonder if capturing standard output from Perspective scoped stuff automatically is more doable than we thought...
I'll put in a ticket to investigate this further.

5 Likes

Couldn't you just use

self.print("some message?")
4 Likes

I didn't know this little gem existed!!! It does look like it prints an entire view path which could be helpful or cluttering in some cases.

One benefit of a separate function is that you can then log those messages and/or insert into a help desk database if need be, all from one place. Not really for debugging, but for client-side issues in an already-deployed app.

Thank you for this tip!