+ Post New Thread
Results 1 to 12 of 12
Coding Thread, Papercut Scripts in Coding and Web Development; Not sure if this is the right place for this... but! Does anyone have any idea how to write papercut ...
  1. #1
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7

    Papercut Scripts

    Not sure if this is the right place for this... but!

    Does anyone have any idea how to write papercut scripts. The school want to restrict colour printing on all accounts that are visible. colour printing can then only be done with a pin number, which the teacher will have to put in. What i need is the accounts to convert to grey scale automatically. So does anyone have any idea how to convert an "account" (not a group) to grey scale? I had the below from papaercut support but i'm a little lost on this one.

    It would work in conjunction with a print script that would force all jobs to be converted to black & white.

    You could use the input "inputs.job.selectedSharedAccountName" then force the conversion based on the account.

    There is already a recipe available within the "Scripting" tab which is found against the printer in PaperCut which you could use a foundation.

    "Discounted printing for selected shared account"


    Any help would be massively appreciated.

    Many Thanks

  2. #2
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7
    Anyone

  3. #3
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Location
    Powys, Wales
    Posts
    607
    Thank Post
    67
    Thanked 131 Times in 102 Posts
    Rep Power
    43
    I found this one on our papercut:

    "Color print jobs require user confirmation"


    Code:
    /*
    * Color print jobs require user confirmation
    *
    * Color printing is expensive so users should be encouraged to print
    * in grayscale whenever they print in color. No confirmation is required
    * for grayscale jobs.
    */
    function printJobHook(inputs, actions) {
    /*
    * This print hook will need access to all job details
    * so return if full job analysis is not yet complete.
    * The only job details that are available before analysis
    * are metadata such as username, printer name, and date.
    *
    * See reference documentation for full explanation.
    */
    if (!inputs.job.isAnalysisComplete) {
    // No job details yet so return.
    return;
    }
    
    if (inputs.job.isColor) {
    /* Color job, ask the use if they want to print. The job cost is displayed
    * prominently to encourage users to consider black and white printing instead.
    */
    var response = actions.client.promptPrintCancel(
    "<html>This print job is <span style='color:red'><b>color</b></span>"
    + " and costs <b>" + inputs.utils.formatCost(inputs.job.cost)
    + "</b>.  You can save money by printing the job in grayscale.<br><br>" 
    + "Do you want to print this job?</html>",
    {"dialogTitle" : "Color print job", 
    "dialogDesc"  : "Consider printing in grayscale to reduce costs"});
    if (response == "CANCEL" || response == "TIMEOUT") {
    // User did not respond, cancel the job and exit script.
    actions.job.cancel();
    return;
    }
    }
    }
    


  4. #4
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Location
    Powys, Wales
    Posts
    607
    Thank Post
    67
    Thanked 131 Times in 102 Posts
    Rep Power
    43
    Continuation...


    And this one; "Convert jobs with a high number of color pages to grayscale"

    Code:
    /*
    * Convert jobs with a high number of color pages to grayscale (or cancel)
    *
    * Users may accidentally (or without thinking) print multi-page documents with
    * many color pages.  When printing jobs with a high number of colour pages
    * (e.g. >20), users will be given a choice to either convert their job to
    * grayscale or cancel it.  Users who are not running the client software will
    * have their jobs canceled automatically.
    *
    * NOTE: this script requires page-level color detection to be enabled on the
    * printer.
    */
    function printJobHook(inputs, actions) {
    // the maximum number of color pages before prompting to convert / cancel
    var MAX_COLOR_PAGES = 20;
    // message displayed to the user asking if they would like to convert they job
    // to grayscale or cancel it
    var CONVERT_MESSAGE = 'Your job contains more than the maximum allowed '
    + 'number of color pages.  Would you like to '
    + 'convert your job to grayscale?  Selecting "No" will cancel the job.';
    
    /*
    * This script will need access to the number of color pages in the job, which
    * is available after job analysis is complete. If job analysis is not
    * complete we exit here. See the user manual for more details.
    */
    if (!inputs.job.isAnalysisComplete) {
    return;
    }
    
    if (inputs.job.totalColorPages > MAX_COLOR_PAGES) {
    if (inputs.client.isRunning) {
    // User is running the client software. Ask if they want to convert to
    // grayscale or cancel.
    var response = actions.client.promptYesNo(CONVERT_MESSAGE);
    
    if (response == 'NO') {
    actions.log.debug('User chose to cancel their job.');
    actions.job.cancel();
    } else if (response == 'TIMEOUT') {
    actions.log.debug('Dialog timed out, canceling job.');
    actions.job.cancel();
    } else {
    actions.log.debug('User chose to convert their job to grayscale.');
    actions.job.convertToGrayscale();
    }
    } else {
    actions.log
    .debug('Canceling job due to high number of color pages and user '
    + 'not running client software.');
    actions.job.cancel();
    }
    }
    }
    You could combine the two to make one, I would do it but i'm a little busy.

    Just grab the
    actions.job.convertToGrayscale(); and mix it with the other one

  5. #5
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7
    The 2nd one looks good, but im not sure how to make it come up for certain accounts? So if i select the colour account i wouldnt want this box to appear, but if i picked a B/W account i want it to come up... any ideas?

    /*
    * Convert jobs with a high number of color pages to grayscale (or cancel)
    *
    * Users may accidentally (or without thinking) print multi-page documents with
    * many color pages. When printing jobs with a high number of colour pages
    * (e.g. >20), users will be given a choice to either convert their job to
    * grayscale or cancel it. Users who are not running the client software will
    * have their jobs canceled automatically.
    *
    * NOTE: this script requires page-level color detection to be enabled on the
    * printer.
    */
    function printJobHook(inputs, actions) {
    // the maximum number of color pages before prompting to convert / cancel
    var MAX_COLOR_PAGES = 0;
    // message displayed to the user asking if they would like to convert they job
    // to grayscale or cancel it
    var CONVERT_MESSAGE = 'Your job contains more than the maximum allowed '
    + 'number of color pages. Would you like to '
    + 'convert your job to grayscale? Selecting "No" will cancel the job.';

    /*
    * This script will need access to the number of color pages in the job, which
    * is available after job analysis is complete. If job analysis is not
    * complete we exit here. See the user manual for more details.
    */
    if (!inputs.job.isAnalysisComplete) {
    return;
    }

    if (inputs.job.totalColorPages > MAX_COLOR_PAGES) {
    if (inputs.client.isRunning) {
    // User is running the client software. Ask if they want to convert to
    // grayscale or cancel.
    var response = actions.client.promptYesNo(CONVERT_MESSAGE);

    if (response == 'NO') {
    actions.log.debug('User chose to cancel their job.');
    actions.job.cancel();
    } else if (response == 'TIMEOUT') {
    actions.log.debug('Dialog timed out, canceling job.');
    actions.job.cancel();
    } else {
    actions.log.debug('User chose to convert their job to grayscale.');
    actions.job.convertToGrayscale();
    }
    } else {
    actions.log
    .debug('Canceling job due to high number of color pages and user '
    + 'not running client software.');
    actions.job.cancel();
    }
    }
    }

  6. #6

    Join Date
    Jan 2013
    Location
    Wakefield
    Posts
    11
    Thank Post
    1
    Thanked 2 Times in 2 Posts
    Rep Power
    4
    Hi Frut, I may be able to help, but your original request is a little misleading. I'm guessing that we are talking staff and students.
    do you have just two accounts? one for colour and one for mono associated to students
    if so -how does this sound ?
    students can choose which account,
    if they choose MONO then it will come out in mono
    if they choose colour, it will prompt for a code, which if correct will come out in colour
    if the code entered is wrong, it gets cancelled with a message.

    Do you really need colour and mono accounts? you can always report afterwards to see colour and mono work. Your script could do the same thing but with one account.
    Last edited by ukwebb; 21st October 2013 at 10:06 PM.

  7. #7

    Join Date
    Jan 2013
    Location
    Wakefield
    Posts
    11
    Thank Post
    1
    Thanked 2 Times in 2 Posts
    Rep Power
    4
    I think may do what you're after

    it will give the end user a prompt only if they send a colour job :
    Do you really need this in colour?
    if they answer no - it will print it in Mono
    if they answer yes, it will prompt for a release code
    if the code is entered wrong, the job is cancelled
    if correct - it prints

    the code is two digits of the hour and two digits for the current date
    ie 09:00 am on 23 March would yield the code 0923
    giving a code which can be worked out by a staff member, but tricky for the kids to guess at later on as it changes every hour

    hope it helps



    function printJobAfterAccountSelectionHook(inputs, actions) {

    if (!inputs.job.isAnalysisComplete) {
    return;
    }


    if (inputs.job.isColor) {

    var message = '<html><h2 align=center>Do you need this job in Colour?</h2></html>';

    var choices = ["No, Black and White will be fine", "Yes, I need it in Colour"] ;

    var options = {
    'questionID': message.toString(),
    'fastResponse': true,
    'dialogTitle': 'Colour Mode Confirmation',
    'dialogDesc': 'Do you need this job in Colour?',
    'defaultChoice' : "No, Black and White will be fine"
    };

    var ColourMode=actions.client.promptForChoice(message, choices, options);

    if (ColourMode == "No, Black and White will be fine") { // a black and white job has been requested
    actions.job.convertToGrayscale();
    actions.job.addComment('Job Converted to Greyscale');
    return;
    }
    else
    { // a colour job has been requested

    // code is hours and date combined into a four digit number
    var code=new String(inputs.job.date.getHours())+String(inputs.j ob.date.getDate()) ;

    var message = '<html><h2 align=center>Please enter a valid approval code to print this job.</h2></html>';



    // comment this line out after testing - simply displays the passcode for easy debugging
    var message = '<html><h2 align=center>Please enter a valid approval code to print this job.</h2>'+code+'</html>';




    var options = {
    'questionID': message.toString(),
    'fastResponse': true,
    'dialogTitle': 'Enter Approval Code',
    'dialogDesc': 'An approval code is required to print this job.',
    'fieldLabel': 'Approval Code'
    };

    approvalCode = actions.client.promptForPassword(message, options);

    if (approvalCode == 'CANCEL' || approvalCode == 'TIMEOUT' || approvalCode !== code) {
    // user canceled the dialog, took too long to answer or entered a wrong code
    actions.client.sendMessage('No valid approval code entered. ' +
    'Your job will be canceled.');
    actions.job.addComment('No valid approval code entered');
    actions.job.cancel();
    return;
    }
    }
    }


    }


  8. Thanks to ukwebb from:

    Frut02 (25th October 2013)

  9. #8

    Join Date
    Jan 2013
    Location
    Wakefield
    Posts
    11
    Thank Post
    1
    Thanked 2 Times in 2 Posts
    Rep Power
    4
    ps don't forget to remove the line in the middle after testing ;-)

  10. #9
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7
    That's exactly what i was after- perhaps i was asking for the wrong thing... any ideas why there is an error on line 33?

  11. #10
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7
    By the way!! Thank you Thank you Thank you

  12. #11
    Frut02's Avatar
    Join Date
    Oct 2011
    Location
    Cambridge
    Posts
    124
    Thank Post
    4
    Thanked 11 Times in 11 Posts
    Rep Power
    7
    This is what i get

    The script failed to validate, check the script syntax: missing ) after argument list (printer-script#33)

  13. #12

    Join Date
    Jan 2013
    Location
    Wakefield
    Posts
    11
    Thank Post
    1
    Thanked 2 Times in 2 Posts
    Rep Power
    4
    a rogue space seems to have crept in --
    String(inputs.j ob.date.getDate()) ;
    should be
    String(inputs.job.date.getDate()) ;

SHARE:
+ Post New Thread

Similar Threads

  1. Papercut scripting help
    By clareq in forum Network and Classroom Management
    Replies: 13
    Last Post: 29th January 2013, 08:24 PM
  2. PaperCut Scripting Competition
    By Dos_Box in forum Windows Server 2012
    Replies: 0
    Last Post: 4th December 2012, 08:55 AM
  3. Replies: 1
    Last Post: 21st February 2012, 10:54 AM
  4. Papercut Scripts
    By alonebfg in forum Green Computing
    Replies: 1
    Last Post: 5th October 2011, 03:58 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •