There must be something in the air that put the topic of JXA on the minds of the Apple community. Armin Briegel shared a great roundup of recent JXA work, and the #scripting channel on the MacAdmins Slack team is full of folks discussing new and old discoveries.
Here are a handful of additional tips.
Excutable JXA scripts
Save the file with a name and extension you like. I've been using
is the convention suggested by Apple's own Script Editor application. Something
cputype.scpt will work just fine.
Mark the file as executable by running
chmod +x cputype.scpt. Then, you can
run it on your system by simply calling
This will output the CPU architecture of the computer, for example
JXA in Jamf Pro Scripts
You do not necessarily need to wrap JXA in a shell script. It might make sense to "shell out" to a JXA function from a shell script for some use cases, but it is not a requirement.
Jamf supports non-compiled AppleScript files natively, and you can use them in your Policies like any other script.
JXA in Jamf Pro Extension Attributes
Same deal; specify the Script type for the Extension Attribute, and include the
<result></result> wrapper surrounding the output. You can do that with simple
string concatenation using the plus operator, like this:
This will output
<result>ARM64E</result>, for example, which will show up on
your computer's inventory record during the next device inventory.