Output List of Properties and Values

(Tried using search feature on site and didn’t turn up anything relative. Apologies if this has been covered…)

I am trying to write what seems like a simple routine to view all the properties and values of a given file dropped on a script application icon. I’m not sure if this is possible or I’m just not coercing the values correctly to get them to output. I consistantly get variations of the “can’t make” error, generally can’t make the list of properties into string or text, can’t get item x from the properties list, etc.

For example, this one returns the “can’t get item” error (wish I could copy-n-paste the error…grrr…):

on open parseMe
	set parseMeInfo to info for parseMe
	set itemCount to number of items in parseMeInfo as text
	logMe(itemCount, 0)
	repeat with itemNumber from 1 to itemCount
		set itemData to item itemNumber of parseMeInfo
		logMe(name of item itemNumber of parseMeInfo, 0)
	end repeat
end open

logMe is a subroutine I move from script to script for debugging and logging purposes. Modify a few key strings and it’s ready for use:

on logMe(logString, indentLevel)
	set logFilePath to "OSXP:Users:kquosig:Desktop:"
	set logFileName to "LOG-File Info.txt"
	set logFile to (logFilePath & logFileName) as text
	set gReturnChar to "
	tell application "Finder"
			open for access file logFile with write permission
			repeat indentLevel times
				write gTabChar to (logFile as alias) starting at eof
			end repeat
			write (logString & gReturnChar) to (logFile as alias) starting at eof
			close access (logFile as alias)
		on error
			make new file at logFilePath with properties {name:"Diamond Design Monitor.txt"}
			open for access file logFile with write permission
			repeat indentLevel times
				write gTabChar to (logFile as alias) starting at eof
			end repeat
			write (logString & gReturnChar) to (logFile as alias) starting at eof
			close access (logFile as alias)
		end try
	end tell
end logMe

The above script may be a bad example, I tried alot of variations and these later ones were grasping at straws.

I want the script to get a list of properties, figure how many (which is does so far), then output each property and it’s value one by one to a txt file.

Model: PowerPC G5, Dual 1.8 GHxz
AppleScript: 1.9.3
Browser: Internet Explorer 5.23
Operating System: Mac OS X (10.3.9)

I can’t find a way to coerce the records in “info for” into a list of text, but I can help with the “For example, this one returns the “can’t get item” error (wish I could copy-n-paste the error…grrr…):” problem.

When you have some repeatedly erroring script, capture it in a try block:

-- stuff that works
-- stuff that's flakey
on error theError
"The screwup was " & theError -- this will appear in your results or you can log it and look at it there.
end try
-- on with the rest

Looks like it should be simple, doesn’t it, Calvin? However, I suspect the reason you haven’t been flooded with suggestions is that this kind of stuff isn’t quite as straightforward as it might initially seem.

But that also makes it a slightly more interesting challenge. So I thought I’d try cobbling together a script that should (hopefully) get close to what you’ve described. Since it occurs to me that something like this might be of general interest, I’ve posted it in the Code Exchange section, under the heading: Show ‘info for’ properties in a text document.

I hope it helps. :slight_smile:


I didn’t realize until now that the Standard Additions scirpting addition was a package… The labels for the ‘info for’ command must be in the plist? How to get the labels for a particular version of Standard Additions. It’s too bad Apple changes OSs so quickly.


The relevant data is in the “aete” resource of the StandardAdditions.rsrc file - but knowing that doesn’t make it any easier to parse. After that, the specific values from the target file(s) would still need to be extracted and parsed…

Regarding the original question, a different alternative could be this one called “whateverToText”:


OFF-TOPIC: while it doesn’t make “easy” the task, we had in OS 9 EightyLister and we have now ParserTools :smiley:

(But the solutions above are the way to go, anyway)

(Also, if you don’t mind using “Smile” -the free script editor-, you can use its “display” command)

It’s much easier to do this sort of thing in other languages that use dynamic key-value structures like hash arrays rather than fixed-structure records, as you can easily extract keys and values any way you want. For example, in Python (assuming you’ve got appscript installed) you can write a shell script like this:

#!/usr/bin/env pythonw

import sys, macfile
from appscript import *

for path in sys.argv[1:]:
	print path, '\n'
	propertiesDict = app('Finder').items[macfile.Alias(path)].properties()
	for key, value in propertiesDict.items():
		print '\t%s: %r' % (key, value)

and then run it using a command like:

pythonw fileinfoscript.py /some/path /another/path ... > fileinfo.txt

to output a file that looks like this:


	k.comment: ''
	k.file_type: 'APPL'
	k.product_version: u''
	k.everyones_privileges: k.read_only
	k.creation_date: datetime.datetime(2005, 3, 21, 3, 10, 44)

With AppleScript you’re a bit more limited though, since AppleScript doesn’t provide any way to examine the structure of records directly (it’s not how they were intended to be used). Here’s a few possibilities:

  • You could extract each value directly:
set infoStr to "comment: " comment of rec & "
file type: " & file type of rec & ..."

although that’s tedious to write and you’ll still need to format more complex values like lists yourself if you want them to look right.

  • There are also various evil hacks you can use to turn values into strings - e.g. see the Record and ConvertToString libraries on AppleMods - although these aren’t 100% reliable so use at own risk, etc.

  • Another possibility is to use Late Night Software’s List & Record Tools osax to extract property names and values. Note that this’ll only work as long as the record doesn’t contain any application references (a limitation of AppleScript); you’ll be okay with a Standard Additions ‘file information’ record though. You’ll also find that the property names are given as raw 4-letter codes, so if you want to convert those to human-readable names you’ll have to look up that information in Standard Additions’ dictionary. For getting and parsing dictionary resources, use ParserTools from osaxen.com. You’ll still have to do any special string formatting of the values yourself, of course.

  • If you don’t need the data to be presented in a particular format, you can use the ‘format’ command in TextCommands (also on osaxen.com) to turn the record into its literal string representation (the ‘pretty printing’ option may also be useful here). Again, it’ll only work for values that don’t contain any application references, and it can be a little flaky on formatting property names, but if you’re only writing out this stuff for diagnostic purposes then it should do.