Jump to content

XML Import strategy: Apple system profiler


dev_synaptech
 Share

This topic is 5593 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi, I have spent a lot of time today trolling the forum for the best way to attack this project - without any clear idea how to start. I am trying to pull data out of the Apple System Profiler xml file, specificallly, just the hardware info and import into a single record in filemaker. I think I'd like to script it, as the XML structure will be the same accross all machines (all have same OS version).

I've been trying to constuct an XSLT from looking at the Profiler XML data, but I am having troulbe with the nested nature of the data. I'll be pulling in say, 20 attributes (machine name, HD model, memory, etc. etc.)

I am hoping this makes sense and I am looking for a push in the right direction for a way to parse this info.

Thanks!

Cliff

Link to comment
Share on other sites

Here is an excerpt from the man entry for "plist":

PROPERTY LIST XML TAGS

When property lists convert a collection of Core Foundation objects into

an XML property list, it wraps the property list using the document type

tag . The other tags used for the Core Foundation data types are

listed in the table below:

Core Foundation Types with XML Equivalents

CF type XML tag

CFString

CFNumber or

CFDate

CFBoolean or

CFData

CFArray

CFDictionary

When encoding the contents of a CFDictionary, each member is encoded by

placing the dictionary key in a tag and immediately following it

with the corresponding value in the appropriate tag from the table above.

It's kind of an "abstract" form of xml, where what is normally the name of the element is in the element of the line above, and the type of data is in the data's element:

bus_speed

667 MHz

It works very well for lists of things from all different applications. The trick to parsing it as xml, at least that I've found, is to use the:



This gets the next element in line.



Example of the record and 1 field:


						

				

				

							

							

								

									

										

									

								

							

System_Profile_xml.zip

Link to comment
Share on other sites

In the example above I used for xml the output of the command line* (done with AppleScript; because I'm a little Terminally-challenged; also 'cause AppleScript can be run directly from FileMaker, with no plug-in or external file; at least that's my excuse :(-).

do shell script "system_profiler -xml > ~/desktop/SystemProfile.xml"

The above writes it to an xml file (utf-8) on the Desktop. It does not have all the stuff in the System Profile, but most of it. It's about 1/4 the size, and many times faster than System Profiler.

The thing is, the system_profiler command is pretty smart. You can specify which section of data you want. You can get the result as either text (default) or -xml.

set hardware_descr to do shell script "system_profiler SPHardwareDataType"

or

do shell script "system_profiler -xml SPHardwareDataType > ~/desktop/HardwareData.xml""

You can get multipe specified types at once (whitespace separation):

do shell script "system_profiler SPHardwareDataType SPSoftwareDataType SPNetworkDataType SPMemoryDataType"

If you want to see what those data types are:

do shell script "system_profiler -listdatatypes"

Or you pull out just one particular piece, from one section:

do shell script "system_profiler SPHardwareDataType | grep 'Serial Number'| cut -c 22-"

*Not to mention that FileMaker won't import the .spx file which System Profiler exports as is, just 'cause the extension is not .xml.

Link to comment
Share on other sites

This topic is 5593 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.