Using the new manifest properties

Let’s test the script formatting here.

Script Debugger 6 exposes several of the manifest values as properties, allowing you to roll your own manifest report. Here’s an example script to produce a manifest of a document in XML:

use framework "Foundation"
use scripting additions

-- classes, constants, and enums used
property NSXMLDocumentXMLKind : a reference to 0
property NSXMLNodePrettyPrint : a reference to 131072
property NSXMLElement : a reference to current application's NSXMLElement
property NSXMLDocument : a reference to current application's NSXMLDocument

-- get info from SD
tell application id "com.latenightsw.ScriptDebugger6" -- Script Debugger.app
	if not (exists document 1) then
		beep
		display dialog "No document open" buttons {"OK"} default button 1
		error number -128
	end if
	set theResult to compile document 1
	if not theResult then
		beep
		activate
		error number -128
	end if
	set appName to name
	set appVersion to version
	tell document 1
		set docName to name
		set docFile to file spec
		set appNames to used applications
		set additionNames to used scripting additions
		set additionFiles to used scripting addition files
		set libNames to used script libraries
		set libFiles to used script library files
		set frameworkNames to used frameworks
		set frameworkFiles to used framework files
		set embeddedLibs to embedded script libraries
	end tell
	-- get destination
	set theDest to choose file name with prompt "Save Manifest XML report" default name (docName & " manifest.xml")
end tell

-- make root element
set attribs to {creator:appName, |version|:appVersion, |name|:docName}
if docFile is not missing value then set attribs to attribs & {|path|:(POSIX path of docFile)}
set rootElement to NSXMLElement's elementWithName:"manifest"
rootElement's setAttributesWithDictionary:attribs
-- make XML document
set theXMLDocument to NSXMLDocument's alloc()'s initWithRootElement:rootElement
theXMLDocument's setDocumentContentKind:NSXMLDocumentXMLKind
theXMLDocument's setStandalone:true
theXMLDocument's setCharacterEncoding:"UTF-8"
-- build XML
if (count of appNames) > 0 then
	set newElement to NSXMLElement's elementWithName:"applications"
	rootElement's addChild:newElement
	repeat with aName in appNames
		set childElement to (NSXMLElement's elementWithName:"application" stringValue:aName)
		(newElement's addChild:childElement)
	end repeat
end if
if (count of additionNames) > 0 then
	set newElement to NSXMLElement's elementWithName:"scripting_additions"
	rootElement's addChild:newElement
	repeat with i from 1 to count of additionNames
		set childElement to (NSXMLElement's elementWithName:"addition" stringValue:(item i of additionNames))
		set theFile to item i of additionFiles
		if theFile is not missing value then (childElement's setAttributesWithDictionary:{|path|:(POSIX path of theFile)})
		(newElement's addChild:childElement)
	end repeat
end if
if (count of libNames) > 0 then
	set newElement to NSXMLElement's elementWithName:"used_script_libraries"
	rootElement's addChild:newElement
	repeat with i from 1 to count of libNames
		set childElement to (NSXMLElement's elementWithName:"library" stringValue:(item i of libNames))
		set theFile to item i of libFiles
		if theFile is not missing value then (childElement's setAttributesWithDictionary:{|path|:(POSIX path of theFile)})
		(newElement's addChild:childElement)
	end repeat
end if
if (embeddedLibs is not missing value and (count of embeddedLibs) > 0) then
	set newElement to NSXMLElement's elementWithName:"embedded_script_libraries"
	rootElement's addChild:newElement
	repeat with aName in embeddedLibs
		set childElement to (NSXMLElement's elementWithName:"library" stringValue:aName)
		(newElement's addChild:childElement)
	end repeat
end if
if (count of frameworkFiles) > 0 then
	set newElement to NSXMLElement's elementWithName:"frameworks"
	rootElement's addChild:newElement
	repeat with i from 1 to count of frameworkNames
		set childElement to (NSXMLElement's elementWithName:"framework" stringValue:(item i of frameworkNames))
		set theFile to item i of frameworkFiles
		if theFile is not missing value then (childElement's setAttributesWithDictionary:{|path|:(POSIX path of theFile)})
		(newElement's addChild:childElement)
	end repeat
end if
set theNSData to theXMLDocument's XMLDataWithOptions:NSXMLNodePrettyPrint
-- write data to file atomically
set theResult to theNSData's writeToFile:(POSIX path of theDest) atomically:true
beep
2 Likes

7 posts were split to a new topic: Extracting scripts from forum posts

The first thing I did with SD6 was to re-write the header script I used to put an “Attributation” on scripts I write, I used the manifest in SD5 and before. Here’s what it looks like and if anyone wants a look at it, please email me “off list”.

All the data supplied to this is scripted. The script that produces this is rather long so I decided not to post it.

Name: Brand.scptd
Version: 2.4
Compile Date: Saturday, July 9, 2016
Compile Time: 5:53:01 PM
Copyright © 2016 - 2017 'your name or company goes here’
Compiled with: Script Debugger, v6.0
Applications used: Finder, Script Debugger
Scripting Additions used: StandardAdditions.osax
Script Librires used: None
Embedded Librires used: None
Frameworks used: AppKit

Sorry to ask the dummy question, but what is a manifest report / property, and what’s the use case for them?

EDIT: Oh, it’s like a BOM, huh?

Yes, a bit like a BOM. See the File -> Show Manifest… command.

1 Like