├── SotM_1-Trick_or_treat.js ├── SotM_10-Confirm_jobs_with_high_cost.js ├── SotM_11-Webprint_Queue_timeout.js ├── SotM_12-Free_Printing_Keywords.js ├── SotM_13-Select_Release_Account.js ├── SotM_14-Black_Friday_Discounts.js ├── SotM_2-Days_until_Christmas.js ├── SotM_3-Random_Quote.js ├── SotM_4-Colour_Only_Extensions.js ├── SotM_5-Low_Balance_Alert.js ├── SotM_6-April_Fools.js ├── SotM_7-Track_Virtual_Queues.js ├── SotM_8-Disable_Print_Archiving.js ├── SotM_9-Everyone_has_an_opinion.js └── readme.md /SotM_1-Trick_or_treat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Halloween User Trick 3 | * 4 | * Cancel or charge double for some jobs from a certain user 5 | * 6 | * Read more at https://www.selectec.com/script-of-the-month-1-halloween-trick/ 7 | */ 8 | 9 | function printJobHook(inputs, actions) { 10 | 11 | if ( !inputs.job.isAnalysisComplete ) { 12 | // No job details yet so return. 13 | return; 14 | } 15 | 16 | // The user we want to mess with 17 | var username = "Ross"; 18 | // Get the seconds from the time the job was sent 19 | var seconds = inputs.job.date.getSeconds(); 20 | 21 | if ( inputs.job.username == username ) { 22 | // If 11 or 22 seconds 23 | if ( seconds == 11 || seconds == 22 ) { 24 | // Cancel the job and let the user know 25 | actions.job.cancel(); 26 | actions.client.sendMessage( "Sorry the job has been cancelled" ) 27 | // Else If seconds is 33 or 44 28 | } else if ( seconds == 33 || seconds == 44 ) { 29 | // Double the cost of his job and a comment to the job 30 | actions.job.setCost( inputs.job.cost * 2 ); 31 | actions.job.addComment( "Cost doubled for Halloweeen trick" ) 32 | } else { 33 | // Don't do anything 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SotM_10-Confirm_jobs_with_high_cost.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Ask users to confirm the print job if over a certain cost 3 | * 4 | * Read more at https://www.selectec.com/script-of-the-month-10-confirm-jobs-high-cost/ 5 | */ 6 | 7 | function printJobHook(inputs,actions) { 8 | // What is our limit for alerts? 9 | var COST = 1.0; 10 | // This is the message we will show the users 11 | var MESSAGE = "This job costs over £" + COST + " are you sure you want to print it?"; 12 | 13 | if (!inputs.job.isAnalysisComplete) { 14 | return; 15 | } 16 | 17 | // Check the job cost 18 | if (inputs.job.cost >= COST) { 19 | // Show the prompt and set the response to the response variable 20 | var response = actions.client.promptPrintCancel(MESSAGE); 21 | // If user clicked Cancel or there was a timeout 22 | if (response == "CANCEL" || response == "TIMEOUT") { 23 | // Cancel the job and exit the script 24 | actions.job.cancel(); 25 | return; 26 | } 27 | // User pressed print so we will let the job go 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /SotM_11-Webprint_Queue_timeout.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Hold Web Print jobs for longer over the weekend 3 | * 4 | * Read more at https://www.selectec.com/papercut-print-script-month-11-setting-queue-timeout-webprint/ 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | var today = new Date(); 9 | 10 | // If job is from Web Print 11 | if (inputs.job.jobSourceName == "WEB_PRINT") { 12 | // If today is Saturday or Sunday 13 | if (today.getDay() == 6 || today.getDay() == 0) { 14 | // Set hold timeout to 2880 minutes 15 | actions.job.setHoldReleaseTimeout(2880); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SotM_12-Free_Printing_Keywords.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Keyword(s) = Free Printing 3 | * 4 | * Read more at https://www.selectec.com/papercut-print-script-month-12-keywords-free-printing/ 5 | */ 6 | 7 | function printJobHook( inputs, actions ) { 8 | // Comment to apply to job 9 | var JOB_COMMENT = "Free Print Job Roald Dahl 100th Anniversary"; 10 | 11 | // Array of Book Names 12 | var BOOK_NAMES = [ 13 | "The Gremlins", 14 | "Over To You", 15 | "Some Time Never", 16 | "Someone Like You", 17 | "Kiss Kiss", 18 | "James and the Giant Peach", 19 | "Charlie and the Chocolate Factory", 20 | "The Magic Finger", 21 | "Fantastic Mr Fox", 22 | "Charlie and the Great Glass Elevator", 23 | "Danny, the Champion of the World", 24 | "The Wonderful Story of Henry Sugar and Six More", 25 | "The Enormous Crocodile", 26 | "My Uncle Oswald", 27 | "The Twits", 28 | "George's Marvellous Medicine", 29 | "Revolting Rhymes", 30 | "The BFG", 31 | "Dirty Beasts", 32 | "The Witches", 33 | "Roald Dahl’s Book of Ghost Stories", 34 | "Boy: Tales of Childhood", 35 | "The Giraffe and the Pelly and Me", 36 | "Two Fables", 37 | "Going Solo", 38 | "Matilda", 39 | "Rhyme Stew", 40 | "Ah, Sweet Mystery of Life", 41 | "Esio Trot", 42 | "The Vicar of Nibbleswicke", 43 | "The Minpins", 44 | "Roald Dahl's Guide to Railway Safety", 45 | "My Year" 46 | ]; 47 | 48 | if (!inputs.job.isAnalysisComplete) { 49 | // No job details yet so return. 50 | return; 51 | } 52 | 53 | // If jobname matches any of the book names 54 | if (matchesAny(inputs.job.documentName.toLowerCase(), BOOK_NAMES)) { 55 | // Add comment to job 56 | actions.job.addComment(JOB_COMMENT); 57 | // Set the cost to 0 58 | actions.job.setCost(0); 59 | } 60 | } 61 | 62 | // Function borrowed from PaperCut Recipe (Confirm printing emails in color (from Outlook)) 63 | function matchesAny(str, matchStrs, actions) { 64 | if (str == null || matchStrs == null) { 65 | return false; 66 | } 67 | 68 | for (var i in matchStrs) { 69 | if (str.match(matchStrs[i]).toLowerCase()) { 70 | return true; 71 | } 72 | } 73 | 74 | return false; 75 | } 76 | -------------------------------------------------------------------------------- /SotM_13-Select_Release_Account.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Select Release Account 3 | * 4 | * Read more at https://www.selectec.com/papercut-print-script-month-13-select-release-account/ 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | 9 | // Users that can be selected from the dropdown 10 | var USERS = ["none", "bwayne", "tstark", "pparker", "ballen", "oqueen", "ckent"]; 11 | 12 | // Group to apply script to 13 | var GROUP = "students"; 14 | 15 | // Message to show in the popup 16 | var MESSAGE = "Please select an account below to allow that user to release your job."; 17 | 18 | // Popup Title 19 | var TITLE = "Select an account"; 20 | 21 | // Popup options 22 | var OPTIONS = {'dialogTitle': TITLE, 'defaultChoice': 'none', 'fieldLabel': 'Accounts', 'hideJobDetails': true}; 23 | 24 | // As always we will wait for analysis just to make sure there are no problems 25 | if (!inputs.job.isAnalysisComplete) { return; } 26 | 27 | // If user is not in the students group exit the script 28 | if (!inputs.user.isInGroup(GROUP)) { return; } 29 | 30 | // Get the response from the prompt and set the default value to none 31 | var response = actions.client.promptForChoice(MESSAGE, USERS, OPTIONS); 32 | 33 | // If the selection is not none 34 | if (response != 'none') { 35 | // Change the user 36 | actions.job.changeUser(response); 37 | } 38 | 39 | // We don't need to do anything here 40 | } 41 | -------------------------------------------------------------------------------- /SotM_14-Black_Friday_Discounts.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Black Friday 3 | * 4 | * Read more at https://www.selectec.com/papercut-print-script-of-the-month-14-black-friday/ 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | 9 | // Make sure analysis is complete 10 | if (!inputs.job.isAnalysisComplete) {return;} 11 | 12 | // Normal Discount Amount - default 5% 13 | var DISCOUNT_PERCENT = 0.95; 14 | // Discount Amount for "Flash sales" - default 10% 15 | var FLASH_SALE_PERCENT = 0.90; 16 | // Comment to show in job log 17 | var JOB_COMMENT = "Black Friday Discount"; 18 | // Message to show the users for normal sale 19 | var SALE_MESSAGE = "Black Friday Deal - This print job will only cost you '" + inputs.job.cost * DISCOUNT_PERCENT + "'"; 20 | // Message to show the users when the flash sale is on 21 | var FLASH_SALE_MESSAGE = "Black Friday Flash Sale - This print job will only cost you '" + inputs.job.cost * FLASH_SALE_PERCENT + "'"; 22 | // Hour to start flash sale - Default 12pm 23 | var FLASH_START = 16; 24 | // Hour to end flash sale - Default 1pm 25 | var FLASH_END = 17; 26 | // Set flash sale to false 27 | var FLASH_SALE = false; 28 | 29 | // Work out if it is time for a flash sale 30 | if (inputs.job.date.getHours() >= FLASH_START && inputs.job.date.getHours() < FLASH_END) { 31 | // Enable the flash sale 32 | FLASH_SALE = true; 33 | } 34 | 35 | // If flash sale time 36 | if (FLASH_SALE) { 37 | // Display the Flash Sale Message 38 | actions.client.promptOK(FLASH_SALE_MESSAGE,{'hideJobDetails': true}); 39 | // Set the new cost of the job 40 | actions.job.setCost(inputs.job.cost * FLASH_SALE_PERCENT); 41 | } else { 42 | // Display normal deal Message 43 | actions.client.promptOK(SALE_MESSAGE,{'hideJobDetails': true}); 44 | // Set the new cost of the job 45 | actions.job.setCost(inputs.job.cost * DISCOUNT_PERCENT); 46 | } 47 | 48 | // Add comment to job so we remember why there was as discount 49 | actions.job.addComment(JOB_COMMENT); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /SotM_2-Days_until_Christmas.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Days until Christmas 3 | * 4 | * Show the users how many days there are until Christmas 5 | * 6 | * Read more at http://www.selectec.com/script-of-the-month-2-days-until-christmas 7 | */ 8 | 9 | function printJobHook( inputs, actions ) { 10 | if ( !inputs.job.isAnalysisComplete ) { 11 | // No job details yet so return. 12 | return; 13 | } 14 | 15 | var objDate = new Date(); // New date object 16 | xmas = Date.parse( "Dec 25, " + objDate.getFullYear() ); // This is the date we want 17 | today = Date.parse( objDate ); // What is todays date again? 18 | daysToGo = Math.round( ( xmas - today ) / ( 1000 * 60 * 60 * 24 ) ); // Little bit of math 19 | 20 | if ( daysToGo == 0 ) { 21 | // It must be xmas today 22 | actions.client.sendMessage( "Merry Christmas!" ); 23 | return; 24 | } 25 | 26 | if ( daysToGo < 0 ) { 27 | // Xmas has gone 28 | actions.client.sendMessage( "We hope you had a good Christmas" ); 29 | return; 30 | } 31 | 32 | if ( daysToGo > 0 ) { 33 | // It is almost xmas time 34 | actions.client.sendMessage( "Christmas is only " + daysToGo + " days away" ); 35 | return; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /SotM_3-Random_Quote.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Random Quote 3 | * 4 | * Show a random quote when a user prints 5 | * 6 | * Read more at http://www.selectec.com/script-of-the-month-3-random-quote/ 7 | */ 8 | 9 | function printJobHook( inputs, actions ) { 10 | 11 | if (!inputs.job.isAnalysisComplete) { 12 | // No job details yet so return. 13 | return; 14 | } 15 | 16 | // Array of quotes 17 | var quotes = [ 18 | "Things work out best for those who make the best of how things work out. ~John Wooden", 19 | "If you are not willing to risk the usual you will have to settle for the ordinary. ~Jim Rohn", 20 | "All our dreams can come true if we have the courage to pursue them. ~Walt Disney", 21 | "Success is walking from failure to failure with no loss of enthusiasm. ~Winston Churchill", 22 | "Try not to become a person of success, but rather try to become a person of value. ~Albert Einstein", 23 | "Great minds discuss ideas; average minds discuss events; small minds discuss people. ~Eleanor Roosevelt", 24 | "I have not failed. I've just found 10,000 ways that won't work. ~Thomas A. Edison", 25 | "The whole secret of a successful life is to find out what is one's destiny to do, and then do it. ~Henry Ford", 26 | "What seems to us as bitter trials are often blessings in disguise.~ Oscar Wilde", 27 | "The distance between insanity and genius is measured only by success. ~Bruce Feirstein", 28 | "If you can't explain it simply, you don't understand it well enough. ~Albert Einstein", 29 | "Innovation distinguishes between a leader and a follower. ~Steve Jobs", 30 | "The starting point of all achievement is desire. ~Napolean Hill", 31 | "Courage is resistance to fear, mastery of fear - not absense of fear. ~Mark Twain", 32 | "Only put off until tomorrow what you are willing to die having left undone. ~Pablo Picasso", 33 | "You must expect great things of yourself before you can do them. ~Michael Jordan", 34 | "Failure is the condiment that gives success its flavor. ~Truman Capote", 35 | "Life is 10% what happens to me and 90% of how I react to it. ~Charles Swindoll", 36 | "Believe you can and you’re halfway there. ~Theodore Roosevelt", 37 | "Do or do not. There is no try. ~Yoda", 38 | "The only way to do great work is to love what you do. ~Steve Jobs", 39 | "We can’t help everyone, but everyone can help someone. ~Ronald Reagan" 40 | ]; 41 | 42 | // Send message to the PC Client with a random quote from the array 43 | actions.client.sendMessage( quotes[ Math.floor( Math.random() * quotes.length ) ] ); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /SotM_4-Colour_Only_Extensions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Only allow printing when using certain file extensions 3 | * 4 | * Read more at http://www.selectec.com/script-of-the-month-4-color-only-extensions 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | 9 | if (!inputs.job.isAnalysisComplete) { 10 | return; 11 | } 12 | 13 | var fileExtensions = [ ".xls", ".ppt", ".doc", ".xlsx", ".pptx", ".docx" ]; 14 | 15 | if (inputs.job.isColor){ 16 | for (i = 0; i < fileExtensions.length; i++) { 17 | if (inputs.job.documentName.indexOf( fileExtensions[i] ) !== -1 ) { 18 | return; 19 | } 20 | } 21 | actions.client.sendMessage( "Colour jobs must be .xls(x), .ppt(x), .doc(x). Cancelling Job!" ); 22 | actions.job.cancel(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SotM_5-Low_Balance_Alert.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Email user when balance is low 3 | * 4 | * Read more at https://selectec.com/script-of-the-month-5-low-balance-alert/ 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | 9 | var LOW = 1; 10 | var SUBJECT = "Your balance is low"; 11 | var BODY = "Your PaperCut Balance is getting low, Don't forget to top up soon or you won't be able to print"; 12 | 13 | if (!inputs.job.isAnalysisComplete) { 14 | return; 15 | } 16 | 17 | if ( inputs.user.balance - inputs.job.cost <= LOW ) { 18 | actions.utils.sendEmail(inputs.user.email, SUBJECT, BODY); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SotM_6-April_Fools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Send print jobs to random printer 3 | * 4 | * Read more at http://www.selectec.com/script-of-the-month-6-april-fools-2016/ 5 | */ 6 | 7 | function printJobHook( inputs, actions ) { 8 | 9 | if (!inputs.job.isAnalysisComplete) { 10 | // No job details yet so return. 11 | return; 12 | } 13 | 14 | // Array of printers 15 | var printers = ['science_room','maths_room','english_room']; 16 | actions.job.redirect(printers[ Math.floor( Math.random() * printers.length ) ], {recalculateCost: true}); 17 | } 18 | -------------------------------------------------------------------------------- /SotM_7-Track_Virtual_Queues.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Track sheets printed on virtual queue 3 | * 4 | * Read more at https://selectec.com/script-of-the-month-7-count-virtual-queue-sheets/ 5 | */ 6 | 7 | function printJobHook(inputs, actions) { 8 | 9 | if (!inputs.job.isAnalysisComplete) { 10 | // No job details yet so return. 11 | return; 12 | } 13 | 14 | // Show current sheets 15 | actions.client.promptOK('So far "' + inputs.utils.getNumberProperty('green-queue') + '" pages have been printed using this queue'); 16 | 17 | // Increment green-queue by total sheets in job 18 | actions.utils.onCompletionIncrementNumberProperty('green-queue', inputs.job.totalSheets) 19 | } 20 | -------------------------------------------------------------------------------- /SotM_8-Disable_Print_Archiving.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Allow a group of users to disable Archiving 3 | * 4 | * Read more at https://selectec.com/script-of-the-month-8-disable-print-archiving/ 5 | */ 6 | 7 | function printJobHook( inputs, actions ) { 8 | 9 | var GROUP = "HR"; 10 | var MESSAGE = "Do you want to disable archiving for this job?"; 11 | var COMMENT = "This job was considered sensitive and archiving was disabled"; 12 | 13 | if (!inputs.job.isAnalysisComplete) { 14 | return; 15 | } 16 | 17 | if (inputs.user.isInGroup(GROUP)) { 18 | var RESP = actions.client.promptYesNo( MESSAGE ); 19 | 20 | if (RESP == "TIMEOUT") { 21 | actions.job.cancel(); 22 | return; 23 | } 24 | 25 | if (RESP == "YES"){ 26 | actions.job.disableArchiving(); 27 | actions.job.addComment(COMMENT); 28 | return; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /SotM_9-Everyone_has_an_opinion.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Ask users to vote on important things like staying in the EU 3 | * 4 | * Read more at https://www.selectec.com/script-of-the-month-9-everyone-has-an-opinion/ 5 | */ 6 | 7 | function printJobHook(inputs,actions) { 8 | 9 | // Prompt Title 10 | var TITLE = "Referendum on the United Kingdom's membership of the European Union"; 11 | // What question are we going to ask? 12 | var QUESTION = "Should the United Kingdom remain a member of the European Union or leave the European Union?"; 13 | // Array of possible choices 14 | var CHOICES = ["Remain", "Leave", "Undecided"]; 15 | 16 | // Dictionary containing Prompt options 17 | var OPTIONS = { 18 | 'defaultChoice' : 'Undecided', 19 | 'hideJobDetails' : true, 20 | 'dialogDesc' : QUESTION, 21 | 'dialogTitle' : TITLE 22 | } 23 | 24 | // Analysis has not completed return 25 | if (!inputs.job.isAnalysisComplete) { 26 | return; 27 | } 28 | 29 | 30 | // Show the prommpt and set the response to vote 31 | var vote = actions.client.promptForChoice('', CHOICES, OPTIONS); 32 | 33 | // We are not bothered by Timeouts or those who don't want to vote 34 | if (vote == "TIMEOUT" || vote == "CANCEL") { 35 | return; 36 | } 37 | 38 | // Loop choices 39 | for (i = 0; i < CHOICES.length; i++) { 40 | // If vote = choice 41 | if (vote == CHOICES[i]) { 42 | // increase vote.[users-choice] by 1 43 | actions.utils.onCompletionIncrementNumberProperty('vote.' + vote, 1); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # PaperCut Print Scripts 2 | 3 | These are the print scripts to go along with our Script of the Month blog feature, You can read more about each script by following the link below. 4 | 5 | [https://www.selectec.com/select/scripting/](https://www.selectec.com/select/scripting/) 6 | --------------------------------------------------------------------------------