Jump to content

Recommended Posts

Posted

I have taken one of the pre-built recipes Papercut provide (Charge printing during class time to the department) and amended it.

 

Any ideas why it wont work? The groups and the shared account are for testing. The user I am using is a member of staff.

 

 

 

//

// Customize your print process with Print Scripting. You don't have to be a

// programmer to use Print Scripting. Use one of the many pre-written recipes

// already written for you, or write your own in JavaScript using snippets and

// reference documentation.

//

function printJobHook(inputs, actions) {

/*

* Members of the staff get free printing to IT printers

* during lab time (9:00am to 4:00pm weekdays).

*/

function printJobHook(inputs, actions) {

 

var MONDAY = 1; // 0 = Sunday, 1 = Monday

var FRIDAY = 5;

 

var day = inputs.job.date.getDay();

var hour = inputs.job.date.getHours();

 

if (day >= MONDAY && day <= FRIDAY

&& (hour >= 9 && hour < 16)

&& inputs.user.isInGroup("STAFF")) {

 

}

 

 

// Charge the job to the "Year Leaders" shared account.

actions.job.chargeToSharedAccount("Year Leaders");

}}

  • Thanks 1
Posted
Any reason you're opening up the function twice?

 

function printJobHook(inputs, actions) {

 

I have no idea!! I just took the script and amended it to what I thought would work. There were no errors and it save successfully. It just doesn't do what I want it to do.

 

I will edit out the first one and see what happens.

Posted
You're welcome :)

@EJWill - Do you use scripts in your papercut setup? If so would you be willing to share any interesting ones you have? They may be useful to us.

Posted
I designed an all encompassing one for our school, which detects if it's a colour print job and if it's more than 1 page so it then asks to make the job mono and duplex. if you're interested?
Posted
I designed an all encompassing one for our school, which detects if it's a colour print job and if it's more than 1 page so it then asks to make the job mono and duplex. if you're interested?

 

Yes. Sounds interesting.

Posted

Are you certain it's working? Have you tried with a non-staff account?

 

I don't use PaperCut, but general scripting experience leads me to believe your IF statement has no effect - usually any actions to be carried out must be contained within the statement, which would make the above script (with the already found fix):

 

/* 
* Members of the staff get free printing to IT printers 
* during lab time (9:00am to 4:00pm weekdays).
*/
function printJobHook(inputs, actions) {

var MONDAY = 1; // 0 = Sunday, 1 = Monday
var FRIDAY = 5;

var day = inputs.job.date.getDay(); 
var hour = inputs.job.date.getHours();

if (day >= MONDAY && day <= FRIDAY
&& (hour >= 9 && hour < 16)
&& inputs.user.isInGroup("STAFF")) {
   // Charge the job to the "Year Leaders" shared account.
   actions.job.chargeToSharedAccount("Year Leaders");
}

}

 

That is assuming that the intention is for staff printing to be charged to year leaders between 9 and 4, Monday to Friday.

  • Thanks 1
Posted
Yes. Sounds interesting.

 

/*
#  Custom Papercut Script by William 'EJWill' Baldwin
#  Created for Manshead Upper School, Dunstable Rd, Caddington
*/
function printJobHook(inputs, actions) {
 
 
 /*
 ######################################################################
 Defining Attributes and Variables
 ######################################################################
 */
 
 // Variables to easily disable rules if need too.
 // Set a variable to false if you need to disable it.
 // Some will be work in progress and not presently used.
 var DISCOURAGE_SIMPLEX_COLOUR_PRINTING = true;
 var DISCOURAGE_COLOUR_PRINTING = true;
 var DISCOURAGE_SIMPLEX_GREYSCALE_PRINTING = true;
 
 
 //Defined static variables.
 var MAX_COLOUR_PAGES = 0;  //Defines maximum number of colour pages before being discouraged.
 //var MAX_PAGES = 30;      //Defines maximum number of pages before being discouraged.
 //var MAX_COPIES = 2;      //Defines maximum number of copies allowed before being discouraged.
 
 
 //Define variables for string use later. Such as showing a thank you message or recording
 //data in the print logs.
 var showThankYou = false;
 var showMessages = false;
 //var writeToLog = false;
 
 //If we're unable to get all the details of the job, then exit.
 if (!inputs.job.isAnalysisComplete) {
   return;
 }
 
 //Start of the pop up form.
 var strForm = "" 
     + ""
     + ""
     + "Print Policy Alert
http://%PC_SERVER%/images/icons/24x24/warning.png"
     + ""
     + ""
     + "Please help us save toner and paper!"
     + ""
     + ""
     + "Did you know that printing in colour and single paged (Simplex) costs much more than printing Black & White and double paged (Duplex). Help us reduce the environmental impact of printing."
     + ""
     + "Your job will produce " + inputs.utils.formatNumber(inputs.job.environmentGramsCO2, 0) + " grams of CO2? This is equivalent to leaving a 60W bulb on for " + inputs.utils.formatNumber(inputs.job.environmentBulbHours, 1) + " hours!"
     + ""
     + "What does that mean?"
     + ""
     + "Duplex - Printing on both sides of a page."
     + "Simplex - Printing on only one side of a page."
     + ""
     + ""
     + "Would you like to convert your job to a more environmentally friendly setting?"
     + ""
     + "";
 
 
 /*
 ######################################################################
 Capturing and Modifying Print Jobs
 ######################################################################
 */
 
 
 /*
 ------------------------------------------------------------------------------------------------------
 If Job is more than the max colour pages before being discouraged and is not in duplex.
 ------------------------------------------------------------------------------------------------------
 */
 if (DISCOURAGE_SIMPLEX_COLOUR_PRINTING && inputs.job.totalColorPages > MAX_COLOUR_PAGES && !inputs.job.isDuplex){
   
   var strFormActions = strForm 
       + ""
       + "Actions"
       + ""
       + ""
       + ""
       + "Convert to Greyscale"
       + "I understand, but this needs to be in colour"
       + ""
       + ""
       + ""        
       + ""
       + "Convert to Duplex"
       + "I understand, but this needs to be single paged"
       + ""
       + ""
       + ""
       + ""
       + ""
       + "";
   
   response = actions.client.promptForForm(strFormActions,
                                           {
                                             'dialogTitle': 'Print Information',
                                             'dialogDesc': inputs.job.documentName,
                                             'hideJobDetails': true,
                                             'fastResponse': true
                                           }
                                          );
   
   if (response["action"] == "convert" && response["action2"] == "convert"){
     // Convert to Greyscale and Duplex
     actions.job.convertToGrayscale();
     actions.job.convertToDuplex();
     
   } else if (response["action"] == "dont-convert" && response["action2"] == "convert"){
     // Convert to Duplex
     actions.job.convertToDuplex();
     
     if (showMessages){
       actions.client.sendMessage("Please consider using Greyscale for your next job.");
     }
     
   } else if (response["action"] == "convert" && response["action2"] == "dont-convert"){
     // Convert to Greyscale
     actions.job.convertToGrayscale();
     
     if (showMessages){
       actions.client.sendMessage("Please consider using Duplex for your next job.");
     }
     
   } else if (response["action"] == "dont-convert" && response["action2"] == "dont-convert"){
     // Do not Convert
     
     if (showMessages){
       actions.client.sendMessage("Please consider using Greyscale and Duplex for your next job.");
     }
     
   } else if (response == "CANCEL" || response == "TIMEOUT") {
     // Timeout or Cancel
     
     actions.job.cancel();
     return;
   }  
   
 }
 
 
 /*
 ------------------------------------------------------------------------------------------------------
 If job is duplex but also colour.
 ------------------------------------------------------------------------------------------------------
 */
 if (DISCOURAGE_COLOUR_PRINTING && inputs.job.totalColorPages > MAX_COLOUR_PAGES && inputs.job.isDuplex){
   
   var strFormActions = strForm 
       + ""
       + "Actions"
       + ""
       + ""        
       + ""
       + "Convert to Greyscale"
       + "I understand, but this needs to be in colour"
       + ""
       + ""
       + ""
       + ""
       + ""
       + "
";
   
   response = actions.client.promptForForm(strFormActions,
                                           {
                                             'dialogTitle': 'Print Information',
                                             'dialogDesc': inputs.job.documentName,
                                             'hideJobDetails': true,
                                             'fastResponse': true
                                           }
                                          );
   
   if (response["action"] == "convert") {
     // Convert to Duplex
     actions.job.convertToGrayscale();
     
   } else if (response["action"] == "dont-convert"){
     // Do not convert
     if (showMessages){
       actions.client.sendMessage("Please consider using Greyscale for your next job.");
     }
   } else if (response == "CANCEL" || response == "TIMEOUT") {
     // Timeout or Cancel
     actions.job.cancel();
     return;
   }  
   
 }
 
 
 /*
 ------------------------------------------------------------------------------------------------------
 If job is Greyscale but also simplex.
 ------------------------------------------------------------------------------------------------------
 */
 if (DISCOURAGE_SIMPLEX_GREYSCALE_PRINTING && inputs.job.totalGrayscalePages > 1 && !inputs.job.isDuplex){
   
   var strFormActions = strForm 
       + ""
       + "Actions"
       + ""
       + ""        
       + ""
       + "Convert to Duplex"
       + "I understand, but this needs to be single paged"
       + ""
       + ""
       + ""
       + "
"
       + ""
       + "
";
   
   response = actions.client.promptForForm(strFormActions,
                                           {
                                             'dialogTitle': 'Print Information',
                                             'dialogDesc': inputs.job.documentName,
                                             'hideJobDetails': true,
                                             'fastResponse': true
                                           }
                                          );
   
   if (response["action"] == "convert") {
     // Convert to Duplex
     actions.job.convertToDuplex();
     
   } else if (response["action"] == "dont-convert"){
     // Do not convert
     if (showMessages){
       actions.client.sendMessage("Please consider using Duplex for your next job.");
     }
   } else if (response == "CANCEL" || response == "TIMEOUT") {
     // Timeout or Cancel
     actions.job.cancel();
     return;
   }  
   
 }
 
 
 //If showThankYou is true, display message.
 if (showThankYou) {
   actions.client.sendMessage("Thank you for considering the environment!");
 }
 
}

function matchesAny(str, matchStrs, actions) {
 
 if (str == null || matchStrs == null) {
   return false;  
 }
 
 for (var i in matchStrs) {
   if (str.match(matchStrs[i])) {
     return true;
   }
 }
 
}

  • Thanks 2
Posted
Are you certain it's working? Have you tried with a non-staff account?

 

I don't use PaperCut, but general scripting experience leads me to believe your IF statement has no effect - usually any actions to be carried out must be contained within the statement, which would make the above script (with the already found fix):

 

/* 
* Members of the staff get free printing to IT printers 
* during lab time (9:00am to 4:00pm weekdays).
*/
function printJobHook(inputs, actions) {

var MONDAY = 1; // 0 = Sunday, 1 = Monday
var FRIDAY = 5;

var day = inputs.job.date.getDay(); 
var hour = inputs.job.date.getHours();

if (day >= MONDAY && day <= FRIDAY
&& (hour >= 9 && hour < 16)
&& inputs.user.isInGroup("STAFF")) {
   // Charge the job to the "Year Leaders" shared account.
   actions.job.chargeToSharedAccount("Year Leaders");
}

}

 

That is assuming that the intention is for staff printing to be charged to year leaders between 9 and 4, Monday to Friday.

 

Damn it you're right!!! Seems to work for any user. Do I need an Else statement in there?

Posted
Damn it you're right!!! Seems to work for any user. Do I need an Else statement in there?

 

Well using the script I posted, it should charge staff user prints to the "Year Leaders" account during the hours you specified. What I don't know is whether you have to specify default actions...

@EJWill - do you have to do anything to charge the user or will that happen by default after the ptinJobHook function completes if the job hasn't been charged elsewhere?

Posted (edited)
Well using the script I posted, it should charge staff user prints to the "Year Leaders" account during the hours you specified. What I don't know is whether you have to specify default actions...

@EJWill - do you have to do anything to charge the user or will that happen by default after the ptinJobHook function completes if the job hasn't been charged elsewhere?

 

Using your amended script I added an else statement with "actions.job.chargeToPersonalAccount" and it is working exactly how I want it. Staff member prints it is charged to year leaders. Anyone else prints it gets charged to their personal account. Tested and working!

 

Thanks for the heads up.

Edited by fiza
Posted
@EJWill - do you have to do anything to charge the user or will that happen by default after the ptinJobHook function completes if the job hasn't been charged elsewhere?

 

It's done automatically after they accept the print, we use advanced charging set on the printer tab, and set colour and mono to different values.

  • Thanks 1
  • 2 months later...
Posted
Interesting Script EJWill. I have just tried it myself. What doesn't seem to work is the force duplex option, it doesn't matter which drop down I select it will always default to simplex. I am just playing and testing some scripts at the moment and found yours to be very good, and not over the top. Maybe its down to the new version

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...