Script Writing For Mac Image Usiign Jamf



Many scripts perform large and time-consuming processing operations. All too often, they do this invisibly; they simply run and the user has no idea how long processing will take. A more user-friendly approach is to provide progress information during script operation. At a basic level, this can be done by displaying periodic dialogs or notifications. See Displaying Dialogs and Alerts and Displaying Notifications. At a complex level, this can be done by designing a fully-custom interface that provides processing feedback.

AppleScript and JavaScript can also report progress graphically and textually. For script apps, this progress reporting takes the form of a dialog window containing a progress bar, descriptive text, and a Stop button. See Figure 30-1.

In fact, the jamf binary handles this using the recon option: $ sudo jamf recon -assetTag XXXXXX A solution for prompting a user can be as simple as using a call to osascript in a shell script or writing it entirely in AppleScript and submitting the value input by the user. If you use the JAMF Nation link above, look for the script by user emily. It is all that’s needed, provided the Xcode CLI tools are already installed. I have no idea why people love to complicate things so much in their scripts. Noted to update port to webservices URL if not using standard TCP/443 08.21.19 - v2.0. Updated integration to use the JAMF Device Name and Serial Number endpoints in addition to MAC Address. Provided an example of how to extract Macintosh Serial Number via script; 05.23.19 - v1.0. Initial Release; Summary.

For scripts running in Script Editor, this progress reporting appears at the bottom of the script window. See Figure 30-2.

For scripts running from the systemwide script menu, this progress reporting appears in the menu bar, beneath a temporarily displayed gear icon. See Figure 30-3.

AppleScript has several language-level properties and JavaScript has a Progress object with properties that are used to produce this type of progress reporting. See Table 30-1.

Table 30-1Progress properties in AppleScript and JavaScript

AppleScript Property

JavaScript Property

Value Type

Description

progress total steps

Progress.totalUnitCount

Integer

Configures the total number of steps to be reported in the progress. For example, if the script will process 5 images, then the value for progress total steps would be 5.

progress completed steps

Progress.completedUnitCount

Integer

Configures the number of steps completed so far. For example, if the script has processed 3 of 5 images, then the value of progress completed steps would be 3.

progress description

Progress.description

Integer

Text to display when reporting progress. Use this is an opportunity to let the user know what’s happening. For example, it could indicate that images are being processed.

progress additional description

Progress.additionalDescription

Integer

Additional text to display when reporting progress. Use this is an opportunity to provide even more detailed information about what’s happening. For example, it could indicate the specific task being performed, and how much more processing is remaining.

Listing 30-1 and Listing 30-2 demonstrate how these properties can be used to provide progress information while processing a set of images.

Sstf disk scheduling algorithm program in c. APPLESCRIPT

Listing 30-1AppleScript: Display progress while processing images
  1. set theImages to choose file with prompt 'Please select some images to process:' of type {'public.image'} with multiple selections allowed
  2. -- Update the initial progress information
  3. set theImageCount to length of theImages
  4. set progress total steps to theImageCount
  5. set progress completed steps to 0
  6. set progress description to 'Processing Images..'
  7. set progress additional description to 'Preparing to process.'
  8. repeat with a from 1 to length of theImages
  9. -- Update the progress detail
  10. set progress additional description to 'Processing image ' & a & ' of ' & theImageCount
  11. -- Process the image
  12. -- Increment the progress
  13. set progress completed steps to a
  14. -- Pause for demonstration purposes, so progress can be seen
  15. delay 1
  16. end repeat
  17. -- Reset the progress information
  18. set progress total steps to 0
  19. set progress completed steps to 0
  20. set progress description to '
  21. set progress additional description to '

JAVASCRIPT

Listing 30-2JavaScript: Display progress while processing imagesPro
  1. var app = Application.currentApplication()
  2. app.includeStandardAdditions = true
  3. var images = app.chooseFile({
  4. withPrompt: 'Please select some images to process:',
  5. ofType: ['public.image'],
  6. multipleSelectionsAllowed: true
  7. })
  8. // Update the initial progress information
  9. var imageCount = images.length
  10. Progress.totalUnitCount = imageCount
  11. Progress.completedUnitCount = 0
  12. Progress.description = 'Processing Images..'
  13. Progress.additionalDescription = 'Preparing to process.'
  14. for (i = 0; i < imageCount; i++) {
  15. // Update the progress detail
  16. Progress.additionalDescription = 'Processing image ' + i + ' of ' + imageCount
  17. // Process the image
  18. // Increment the progress
  19. Progress.completedUnitCount = i
  20. // Pause for demonstration purposes, so progress can be seen
  21. delay(1)
  22. }

Clicking the Stop button in a progress dialog results in a user cancelled error. Pattern making software for mac.

For additional information, see Progress Reporting in AppleScript Release Notes and Progress in JavaScript for Automation Release Notes.

Note

There’s no need to call a dedicated command to actually display progress information. The act of setting values for the progress properties mentioned above automatically results in progress information being displayed in a dialog, Script Editor, or the menu bar.

While I’m training customers on how to manage their computers with Jamf | Pro, I’m often asked “How can I rename my computers based on a specific naming convention?” My answer often is that, while we do have several ways to rename computers through the GUI, it’s probably not going to fit your needs. However, leveraging the API and a bash script, we can easily achieve what you’re looking for.

I’d like to note that, although most admins want a specific naming convention, upon further questioning it becomes clear that with the power of Jamf Pro at their fingertips, they no longer need a strict naming convention for their computers. Let the users name their computers whatever they want, this is a great step for them to feel that they have ownership of their computer. For instance, at Jamf we do not enforce naming conventions for our computers, and mine is called Photography Raptor, which goes well with my old SLR decal I have on the front of my laptop.

Image

However, there are use cases for strict naming conventions for computers. Maybe you’re binding to AD, and want to know who has what computer based on the computer name from your AD Server. Setting the hostname can also allow you to see which computers are on the network without having to log into Jamf Pro to check. Whatever the case is, here are some options you have available to you (hint, if you want to just know the best way, skip to Scripting a Solution)

If you want to use the Graphical User Interface, your options are going to be somewhat limited. Depending on how you are enrolling your computers, you have different options.

Usb Universal Serial Bus Controller Driver for Windows 7 32 bit, Windows 7 64 bit, Windows 10, 8, XP. Uploaded on 4/17/2019, downloaded 8005 times, receiving a 85/100 rating by 1089 users. AMD SMBUS Driver for Windows 7 (32-bit, 64-bit) - ThinkPad. PC Data Center Mobile: Lenovo Mobile: Motorola Smart Service Parts COMMUNITY. Dalam kasus saya kali ini adalah SM Bus Controller yang belum terpasang/ bermasalah. Spesifikasi komputer yang saya tangani adalah: 1. PC Desktop Merk HP Model 110-010I, Windwos 7 Ultimate 32-bit. Notebook Merk HP Model r120TU, Windows 8.1 32-bit. Untuk mengetahui driver yang belum terpasang, bisa di lihat di Device Manager. SM Chipset Intel / SM Bus Controller: Windows 7, Windows 8, Windows 8.1, Windows 10 32-bit (x86), 64-bit (x64) 2016-10-03 v.10.1.1.38: Intel(R) 4th Gen Core processor DRAM Controller: Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 32-bit (x86), 64-bit (x64) 2013-08-21 v.9.4.0.1027: SM Chipset Intel / SM Bus Controller. Sm Bus Controller Driver for Windows 7 32 bit, Windows 7 64 bit, Windows 10, 8, XP. Uploaded on 3/28/2019, downloaded 5010 times, receiving a 94/100 rating by 2385 users. Dec 18, 2016 - For the smbus controller, download and install the Intel chipset driver from the. Sm Bus Controller Driver Vista 64. Sm bus controller windows 7 64 bit. AMD SMBus device Driver for Windows 8.1 (32-bit, 64-bit), 8 (32-bit, 64-bit) - ThinkPad Edge E135 and X131e.

Prestage Imaging: Prestage imaging allows you to define a scope based on serial number or mac address and preconfigure the imaging settings when Casper Imaging is opened. This is only useful if you are using Net Boot or an external Hard Drive to image your computers. If you’re imaging your computers with one of these methods, you have three options available: Serial Number, Mac Address, or “List of Names.”

Serial Number/Mac Address: This allows you to put a prefix or suffix before the value, but most people want more useful information in the name

List of Names: This may seem tempting, but it’s too simplistic to often be useful. You can write out a list of names, separated by a comma. The Jamf Server will dish out the names based on the order the computers are enrolled, so you don’t really have any control over which computers get which names.

Target Mode Imaging: Target Mode Imaging (TMI) is when you image one computer from another computer through a thunderbolt cable. If you’re imaging If you’re utilizing Casper Imaging via TMI you have several more options at your disposal:

Prompt for each computer: Since you’re touching each computer anyway with TMI, it’s not too big of a step to manually type in the name of the computer, especially if you’re putting an asset tag on it. This can be useful, but is obviously time consuming

Features

Use Numerical Order: This can be useful if you’re batching groups of computers. It allows you to add a prefix and a suffix, and automatically numbers the computers for you. Just image the computers in the order you want them to be in!

Jamf Pro Software

Use Mac Address/Serial: Operates the same as before

Upload CSV File: If you already know what you want your computers name to be based on the serial number, you can upload a CSV file with the serial number in the first column and the desired name in the second column. However, most people don’t have a list like that, they are basically handing out their computers at random.

But let’s say your one of the 95% of users NOT imaging computers before you hand them to clients. The only way you can rename computers is by manually going into the computers inventory record, entering a name, and then deploying a policy to reset the computer names AND update the inventory, which is incredibly tedious. So… let’s look at some other options.

The MUT (short for Mass Update Tool) is an application developed by a Jamf support rep, Mike Levenick. It’s incredibly well documented and has some amazing use cases. It’s a simple tool that utilizes our API to make mass changes based on a serial number. So, you upload a CSV file with the Serial Number in one column and the desired name in the next. However, the computers need to be enrolled before this change takes effect, and you need to know exactly what computers are going where before deploying them.

For more information on how to use The MUT, visit http://jssmut.weebly.com/. It’s very simple and easy to use, and Mike has provided some amazing documentation.

When it comes to renaming computers, scripting a solution is usually the best way, and you’ll see why.

Now, let’s say everyone in your organization gets their own work computer, and that upon enrollment, they are logging in with their LDAP credentials. Let’s say, for this example, that you want the user’s LDAP username and the computer model in the computer name. For example, Randy Johnsmith has a username of rjohns and a 2013 MacBook Air, so his computer should be named:

MBA-rjohns

So, let’s break this down. First off, it starts with an abbreviated model. MacBook Pros will be abbreviated MBP, Airs MBA. After that, it has a dash, then the user’s username. These are all things we easily have access to through the computer, or through the computer’s inventory record.

The Script

So, let’s break this script down. This script will be run on the computer that we are renaming, and I’m going to show you how to script it in bash. Before I even start showing you any commands, let’s make a list of what we need:

  • The serial number of the computer
  • An API call to get all the information in the JSS about the computer
  • Isolation of the username from the API call
  • The model of the computer
  • Abbreviating the model of the computer as MBP or MBA, depending on the model
  • Renaming the computer

Serial Number:

We will start off by putting the serial number of the computer into a variable we call “serialnumber”. This can be achieved through this command:

Using the API to get computer information

We can use the serial number to get the username from the Jamf Pro Server through our API. Now I could spend a good amount of time going into how our API works and what you can do with it, but for this example we are doing a simple GET command to grab information from the computer’s inventory record. Here’s the full command. I’ll use variables to pipe in the unique information:

Let’s break this down a bit:

Curl:

curl is a command used to transfer data to or from the a server. If you run curl https://www.google.com from terminal, you’ll get the source code for the homepage of google (this will probably be mostly unintelligible gibberish, but you should at least get an output). We are using curl to access the API for your Jamf Pro server through https://mycompany.jamfcloud.com/JSSResource/.

-u

This is a flag for the curl command that denotes user credentials

${variable}

When you wrap a variable in ${…}, it outputs the value of that variable in its place. That’s why you’re seeing ${apiusername}, {$apipassword}, ${jssurl} and ${serialnumber} in this script.

/JSSResource/computers/serialnumber/${serialnumber}

MacUsiign

This URL is telling us exactly what part of our API to access. More information can be found by putting /api at the end of your Jamf Pro URL (https://mycompany.jamfcloud.com/api). This will GET all the information for that computer in xml form.

xml=$(…)

This puts all the output from our API request into a variable called xml. This allows us to parse through it later to grab the username and model of the computer.

Username & Model

The next step is to use the xml we gathered before to get the username and model of the computer. We can do that by using the xpath command. It will look like this:

You can easily change the /computer/location/username part of this command to isolate any item within the xml output.

Shortening the Model

The easiest way to shorten the model is through a case statement. I’m not going to go into how a case statement works, I’ve already spent way too much time explaining curl, and how our API works. It’s pretty easy, though, to see what’s happening with this command. I’m taking the output of the model variable, which should be MacBook Pro, MacBook, or MacBook Air, depending on the model, and creating a new variable with a shorter name. Any model that doesn’t match those three will get the abbreviation UNK, for unknown.

Re-naming the computer

And finally, we have everything we need to rename this computer. First off, lets pump our two variables into another variable called computerName. This will look like this:

Next, lets use this variable to rename the computer using the scutil command:

And while we are at it, lets set the hostname as well:

Putting it all together

Now that we’ve gone over each part, lets look at this whole script in action:

Now that you’ve created this amazing looking script, lets show you how to deploy it in your environment!

Deploying the Script

Finally, you are ready to deploy this script to your client computers through Jamf Pro! If you have ever deployed a script through Jamf Pro before, this step should be fairly simple. If you haven’t, I’ll walk you through the steps.

  1. Create the API user account
  2. Add the script to Jamf Pro
  3. Add the script to a policy
  4. Scope the policy to the appropriate computers

Create the API User Account

First off, lets create a user account to access the API. You technically could use your admin account credentials, but since you are typing them in plain text, that is definitely not recommended. Instead, we are going to create an account that has only the credentials it needs to complete the API task.

Go to Settings > JSS User Accounts and Groups > New > Create Standard Account. Name the user something like apiRenameComputer and give it a secure password. Keep the privilege set at custom, then under the privileges window ONLY select Read privileges for computers. Then click Save.

Adding the script to Jamf Pro

In Jamf Pro, go to Settings > Computer Management > Scripts. Then click on New, give the script a name (EG: Renaming Computers), navigate to the Script window, and paste the contents of the script into here. Edit the apiusername, apipassword and jssurl with the correct values. Then click Save.

Adding the script to a Policy

What Is Jamf Software

Next, lets create a policy and add our script to it. Navigate to Computers on the top, then Policies on the left, then select New. Give the policy a name, then scroll down to set a trigger of Recurring Check In and a Frequency of Once Per Computer.

Then go to the Script payload on the left side, click Configure in the middle, and add the script from the list.

Lastly, let’s scope the policy. Go to the scope window, and either scope it to all computers, or target specific computers and either select a group, a building, or a department by clicking Add.

Awesome work – you’ve now mastered renaming computers with Jamf Pro! I’ve added the script we worked on today to my GitHub for your reference, which is complete with error checking and Jamf Parameters, which are both workflows we didn’t have time to get into today. You can view the script at https://github.com/schasta218/Rename-Computer.