Jump to content

Recommended Posts

Posted (edited)

Good Afternoon,

 

we are looking to implement a script where only one user can avoid the convert all emails to greyscale rule.

 

When i print the user who i want to be able to print in colour does so, however so does everyone else! so it is as though the rule is being ignored now!

 

Is someone able to have a quick look over my script and let me know where i have gone wrong? i am assuming it is something simple that i have put in the wrong place!

/*
* Convert all email printing to grayscale except one user.
*
* Implement an organization wide policy that no emails should be printed in
* color.  Often emails contain color in links or headers that adds no value.
* This script automatically converts all emails (printed from Outlook) to
* grayscale. This script will enable 1 or multiple users to be able to print in colour.
*/
function printJobHook(inputs, actions) {
 if (!inputs.job.isAnalysisComplete) {
   return; 
   if (inputs.job.username == "d_coleman"){ 
     return; }
   
   /*
   * Set this to the unique text that appears in the print queue when emails are
   * printed by your organization's email client. This script will work with
   * email applications that use a specific identifiable string in the job
   * title. If the application only uses the email title for instance then this
   * approach will not work.
   */
   var EMAIL_APPLICATION_TITLES = [ 'Microsoft Outlook', 'Microsoft Office Outlook', 'outbind://' ];
   
   // see if the document name matches any of the known email titles
   if (matchesAny(inputs.job.documentName, EMAIL_APPLICATION_TITLES)) {
     // this job is an email, convert it to grayscale (no harm done if the job is
     // already grayscale)
     actions.job.convertToGrayscale();
     
     // if the user is running the client tool we'll send them a courtesy message
     // to let them know
     if (inputs.client.isRunning) {
       actions.client
         .sendMessage('Your email has been automatically converted to '
                      + 'grayscale.');
     }
   }
 }
 
 function matchesAny(str, matchStrs, actions) {
   if (str == null || matchStrs == null) {
     return false;
   }
   
   for ( var i in matchStrs) {
     if (str.match(matchStrs[i])) [color=#88FF88][b]{[/b][/color]
       return true;
     [color=#88FF88][b]}[/b][/color]
   }
   
   return false;
 }
}

Edited by elsiegee40
[code] tags
Posted (edited)

This script allows choosing colour or greyscale. You may have to modify it if its to bypass forced greyscale however.

 

Add it to your virtual queue.

 

 

/*
* 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(
     "This print job is color"
     + " and costs " + inputs.utils.formatCost(inputs.job.cost)
     + ".  You can save money by printing the job in grayscale." 
     + "Press Print to Print in Colour. Press Cancel to convert to Greyscale",
     {"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();
     actions.job.convertToGrayscale();
     
     return;
   }
 }
}

Edited by elsiegee40
Posted (edited)

Dan.. Looking at your script I think the reason it's behaving how it is is because you need a closing brace after the lines

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

The closing brace immediately before the function matchesAny declaration should then be deleted so that the braces still balance.

 

At present the logic to convert jobs to greyscale is all inside the block of the if (!inputs.job.isAnalysisComplete) condition so is all ignored when the script is executed.

 

Please wrap your code in

[/code ] tags in future to preserve formatting - It makes it much easier to read.
Edited by spadam

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...