Guest User

Script

a guest
Jun 14th, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /** Convert all email printing to grayscale
  3. *
  4. * Implement an organization wide policy that no emails should be printed in
  5. * color.  Often emails contain color in links or headers that adds no value.
  6. * This script automatically converts all emails (printed from Outlook) to
  7. * grayscale.
  8. */
  9.  
  10. function printJobHook(inputs, actions) {
  11. /*
  12. * Set this to the unique text that appears in the print queue when emails are
  13. * printed by your organization's email client. This script will work with
  14. * email applications that use a specific identifiable string in the job
  15. * title. If the application only uses the email title for instance then this
  16. * approach will not work.
  17. */
  18.  
  19. if (!inputs.job.isAnalysisComplete) {
  20. // Full job details are not yet available. Return and wait to be called again.
  21. return;
  22. }
  23.  
  24. var EMAIL_APPLICATION_TITLES = [ 'Microsoft Outlook', 'Microsoft Office Outlook', 'outbind://' ];
  25. var CONVERT_MESSAGE = 'Your job contains colour pages. Would you like to convert your job to grayscale? Selecting "No" will print the job in colour, Selecting "YES" will change the job to greyscale.';
  26.  
  27. // See if the document name matches any of the known email titles
  28. if ((inputs.job.isColor) && (matchesAny(inputs.job.documentName, EMAIL_APPLICATION_TITLES))) {
  29.  
  30. // This job is an email, convert it to grayscale
  31. actions.job.convertToGrayscale();
  32.  
  33. // If the user is running the client tool we'll send them a courtesy message
  34. // If they are not, no problems
  35. if (inputs.client.isRunning) {
  36. actions.client.sendMessage('Your email has been automatically converted to grayscale.');
  37. }
  38. }
  39.  
  40. if ((inputs.job.isColor) && (!matchesAny(inputs.job.documentName, EMAIL_APPLICATION_TITLES))) {
  41. // Color job and not an email, ask the use if they want to print.
  42.  
  43. if (inputs.client.isRunning) {
  44. // User is running the client software. Ask if they want to convert to grayscale or cancel.
  45. var response = actions.client.promptYesNo(CONVERT_MESSAGE);
  46.  
  47. if (response == 'NO') {
  48. // User chose to print in color.
  49. actions.log.debug('User chose to keep on printing in color');
  50.  
  51. } else if (response == 'TIMEOUT') {
  52. // Client timed out, cancel the job.
  53. actions.log.debug('Dialog timed out, canceling job.');
  54. actions.job.cancel();
  55.  
  56. } else {
  57. // User chose to convert the job - good work user!
  58. actions.log.debug('User chose to convert their job to grayscale.');
  59. actions.job.convertToGrayscale();
  60. }
  61.  
  62. } else {
  63. // User is not running the client software, so cancel the job.
  64. actions.log.debug('User not running client software.');
  65. actions.job.cancel();
  66. }
  67. }
  68. // Job is Grayscale and not an email, so we will let the job through.
  69. }
  70.  
  71. function matchesAny(str, matchStrs, actions) {
  72. if (str == null || matchStrs == null) {
  73. return false;
  74. }
  75.  
  76. for ( var i in matchStrs) {
  77. if (str.match(matchStrs[i])) {
  78. return true;
  79. }
  80. }
  81.  
  82. return false;
  83. }​
Advertisement
Add Comment
Please, Sign In to add comment