Custom Trigger creation question

tcandela
Valued Contributor II

I created a policy to install Xerox Printer driver, and for the Trigger I set it as Custom and in the text box i entered TESTXeroxDriverCustomTrigger for its name, it will run once per computer.

This is to TEST at this point, so I scoped it to ONE iMac I want to test it on.

I want to create a second policy that will go into Self Service that installs a mapped xerox printer. Instead of putting the xerox print driver in this same policy I will call the Custom Trigger I created earlier. Since I have 4 xerox printers using the same driver I don't want each policy to keep installing the driver each time.

Where in the Second policy do i enter the 'jamf policy -trigger TESTXeroxDriverCustomEvent' command ?? Can I put it in the payload 'Files and Processes' --> 'Execute Command' ? or create a 1 line script with that command and add the script to this policies 'script' payload?

This is how I am thinking it will work and want it to work; if USER A installs Xerox PRINTER 1, it will install the printer and driver. Later if user A needs to install PRINTER 2 it will see that (TESTXeroxDriverCustomTrigger) already ran once on this computer, thus only install the printer.

Will this work?
what gets installed first, the driver or the printer? will it make a difference what gets installed first, the printer will still use the correct driver?

I currently have 4 policies installing the xerox printers and driver in each policy and I'm thinking that creating this custom trigger will cut out installing the same driver more than once on the same computer.

1 ACCEPTED SOLUTION

brandonusher
Contributor II

I've only used scripts, even if they are one line, to fire off custom triggers.

Yes, that should technically work as long as the policy for the driver is set to "Once per Computer", the JSS shouldn't let it run again unless the log is flushed manually.

As for which will install first, that's up to you. When you configure a script to a policy, you can choose Before or After as it's execution sequence. However, if you need the driver installed first then I am not sure how you can be certain the policy ran before executing the policy.

View solution in original post

11 REPLIES 11

brandonusher
Contributor II

I've only used scripts, even if they are one line, to fire off custom triggers.

Yes, that should technically work as long as the policy for the driver is set to "Once per Computer", the JSS shouldn't let it run again unless the log is flushed manually.

As for which will install first, that's up to you. When you configure a script to a policy, you can choose Before or After as it's execution sequence. However, if you need the driver installed first then I am not sure how you can be certain the policy ran before executing the policy.

stevewood
Honored Contributor II
Honored Contributor II

@tcandela I typically apply printer drivers for my Xerox printers to all machines during imaging, regardless of whether they are going to need it or not. In the grand scheme of things, you're only talking a few hundred MB of data on the machine, and does that really amount to much anyway?

As far as how you can trigger the driver to install during a policy, since you want the driver to install before the printer, you would be better off using a script. Although a simple script to call the policy would suffice, you could put a little logic into the script so that it doesn't attempt to load the driver at all.

If the driver policy is set to a frequency of "Once per computer", each subsequent run of the driver policy will amount to "No policy found" during the script run, thus meaning the script to install the driver will not run and will not re-install the driver. Instead the printer policy will continue on with installing the printer.

tcandela
Valued Contributor II

usher.br --- I'm assuming the script that will call the custom event trigger would be easy, I am not a scripting pro, would it be just this?

#!/bin/bash
jamf policy -event TESTXeroxDriverCustomTrigger

so when I add this script to the second policy that adds the printer, set the script to 'BEFORE' and it will do the custom event THEN comeback and install the printer?

stevewood -- valid points. I'm also looking to learn how to use/create custom triggers.

brandonusher
Contributor II

@tcandela Yes, that would be it.

tcandela
Valued Contributor II

awesome, going to test very soon, thanks
i
t automatically gets run as root ? no need for 'sudo'

brandonusher
Contributor II

Correct

yan1212
Contributor

The above suggestions will work and you could go either way (script vs execute command) really.

Another approach that you may find interesting is writing a dummy receipt upon successfully installing the printer (touch /Library/Application Support/JAMF/Receipts/ihavebeentouched.pkg). The advantage here is that this will create a readable value within the JSS that you can manipulate and place computers in smart groups or write extension attributes. This will give you management capabilities beyond only running policies.

There are numerous threads in JAMFNation where people discuss using dummy receipts and some people have done really clever stuff.

Hope this helps.

stevewood
Honored Contributor II
Honored Contributor II

You also do not have to put a trigger name in the "custom" field of the policy. Policies can be executed in one of three ways:

  1. By setting a trigger such as "Check In", "Enrollment", "Login", etc.

  2. By setting a custom trigger after checking "Custom".

  3. By using the policy ID found in the URL of the policy.

A script can have method 1 or method 2 selected, and still be triggered by its ID.

As @yan1212 mentioned, you can use a dummy receipt, or an Extension Attribute, to further scope your policies. In the case of a dummy receipt, touching a file in the JAMF receipts folder, as he mentioned, you can then use the "Packages Installed By Casper" criteria in a Smart Group search. If you use an Extension Attribute, you simply use the Extension Attribute name and value in the Smart Group search.

There are plenty of posts about both of those methods.

stevewood
Honored Contributor II
Honored Contributor II

I forgot to mention the methods for calling the custom trigger and the policy id via a script, just in case you need it:

- to call a custom trigger: jamf policy -trigger <triggername>

- to call via the policy ID: jamf policy -id <id#>

tcandela
Valued Contributor II

good to know also: could go either way (script vs execute command) really.

wakco
Contributor

While I recommend installing driver first then add printer, I've noticed that OS X doesn't care which order they happen in. So your initial idea of add printer then use Execute Command to start the policy to install the driver is perfectly fine, as the added printer will recognise the driver once available.

With the install policy being called from the add printer policy, Self Service will show the policy still executing until the drivers are installed (if needed).