Suspicious Package
Automating with AppleScript
Suspicious Package is a scriptable application, which means that you can automate it using AppleScript.
The Suspicious Package scripting dictionary is thoroughly documented, and contains many bits of sample code. You can open the scripting dictionary from Script Editor, of course, or from within Suspicious Package, a shortcut is to use Help > Open Scripting Dictionary.
If you're using AppleScript in any significant way, we highly recommend checking out the venerable Script Debugger application. While you can get by with the built-in Script Editor application, Script Debugger is more capable and better designed in every way — yes, it costs Actual Money, but it's well worth it.
In addition to AppleScript, there are other scripting dialects that are built upon the same Open Scripting Architecture (OSA) — which is, in turn, built upon the Apple Event technology that dates back to System 7 in the '90s.JavaScript for Automation (JXA) was introduced back in OS X 10.10 (Yosemite), and allows you to use modern JavaScript for communicating with scriptable applications. On the plus side, you get the built-in capabilities of the JavaScript language, including all of the improvements of the last decade, because JXA is built on the same JavaScriptCore framework that underlies Safari. On the downside, JXA itself seems to have been largely neglected in the last decade — although it does still broadly work. Apple has done nothing with JXA documentation since OS X 10.11 (El Capitan), but this site by Christian Kirsch is a fantastic resource.
Alternatively, the Scripting Bridge was introduced back in Mac OS X 10.5 (Leopard), and allows you to use Objective-C for communicating with scriptable applications. For the shrinking number of us that still like Objective-C, the appeal is obvious. But the scripting bridge seems to be neglected about as much as JXA. The API is still described in the active documentation, but important conceptual information — such as how to generate bridging headers — is relegated to the archive.
A few examples of how to use Suspicious Package via AppleScript follow. We've also translated them into the JavaScript for Automation (JXA) dialect; use the buttons at the top of each example to switch between languages.
This first script demonstrates how to open a package — fairly standard AppleScript for targeting a Cocoa application —
and how to get at installed files and folders by name. This also demonstrates how you can use the reveal
command to show
an installed item in a new tab in the Suspicious Package UI:
Suspicious Package also provides a find
command, which can be used to efficiently locate installed files using
a standard AppleScript whose
clause:
You can also use uniform type identifiers (UTIs) to look for related file kinds. Here, we check an item for conformance to com.apple.property-list, which means that any variant on a property list will match:
UTI conformance can also be used within a find
command:
In addition to installed files, AppleScript can also be used to examine the install scripts, and to access the text or other content of each script. In this example, we either examine the text of the script for a particular string, or if the script is a binary executable, we use another app to open the raw binary data:
Finally, in this example, we use the Suspicious Package export
command to get the contents of certain
executable files. Then, we use TextEdit — and some standard command-line tools — to create a report showing
the exported symbols defined by each executable:
The above examples give a flavor of using AppleScript with Suspicious Package, but there are many other properties and elements you can use, including access to package signature information and any potential issues that were flagged for review. Again, check out the scripting dictionary for more information and many more examples.