what are all the file information types?

I’m trying to build an info panel for a selected file.

I’ve been able to get the modification date, size (in scientific notation), and file type but I can’t get the Owner, Dimensions, or other bits of information associated with the file.

Is there way to know all the information attached to a file?

You can use info for to get a bunch of information. It returns stuff like this:


set myInfo to info for myFile

result:
{name:"Invoice Created.pdf", creation date:date "Friday, July 7, 2006 11:42:27 AM", modification date:date "Friday, July 7, 2006 11:42:27 AM", icon position:{0, 0}, size:4.7781E+4, folder:false, alias:false, name extension:"pdf", extension hidden:false, visible:true, package folder:false, file type:"file creator:"displayed name:"Invoice Created.pdf", default application:alias "Brain:Applications:Preview.app:", kind:"PDF Document", locked:false, busy status:false, short version:"", long version:""}

You can get the file owner by telling the Finder:

tell application "Finder" to set theOwner to owner of myFile

When working with files, you need to familiarize youself with the dictionaries for Standard Additions and the Finder. You’ll find a lot of answers in those two dictionaries.

Looking at those dictionary items is very helpful. I think I’m starting to understand how that dictionary reads now. However, I still can’t find information that show under the “more info” heading when I get information about a file in the finder.

Not sure what you’re talking about, I don’t see a “more info” in the Finder, but I’m on Panther instead of Tiger, maybe that’s the difference.

Anyway, there are different things you can find out about a file, depending on if it is a document, a folder, or an application. Here’s an example of the file info you can get in the Finder :

set myFile to choose file without invisibles
set myInfo to {}
tell application "Finder"
	set end of myInfo to file type of myFile
	set end of myInfo to creator type of myFile
	set end of myInfo to stationery of myFile
	set end of myInfo to product version of myFile
	set end of myInfo to version of myFile
end tell
return myInfo

For a document file, that gives you this info:

{"CWSS", "BOBO", false, "", ""}

and for an application:

{"APPL", "adrb", false, "", "3.1.2, Copyright Apple Computer Inc. 2003"}

I think if you look hard enough, you will find all the info you’re looking for, it’s just not in one place because the different files (aliases, documents, applications, folders) each have their own definition.

Hi tdog,

the shell command ‘mdls’ gives you a lot of information (metadata attributes) about a file.
You can use it from AppleScript with

set metaData to (do shell script "mdls " & quoted form of (POSIX path of theFile))

for more information see :
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/mdls.1.html

Maybe also interesting shell commands are file, stat …?

D.

Oh, this is fantastic. I never knew about the md* tools.

So, if I want to transform the mdls return into a hash table how would I do that?

Right now I’m attempting with:

on setFileInfo(file_path)
	set theParams to {}
	set theMetaData to (do shell script "mdls " & quoted form of (POSIX path of file_path))
	set AppleScript's text item delimiters to return
	set metaData_lines to every text item in theMetaData
	repeat with theLine in metaData_lines
		try
			if (offset of "kMD" in theLine) is 1 then
				set AppleScript's text item delimiters to " = "
				set theParams to theParams & {(first text item in theLine), (second text item in theLine)}
			end if
		end try
		log theParams
		
	end repeat
	set AppleScript's text item delimiters to ""
	
end setFileInfo

Is there a hash structure in AppleScript? What’s the best way to go about this?

mainly I’d write it similar to yours. In my attempt I remove the spaces around “=” and filter the "KDM… " lines in the shell script:

	set metaData to {}
	set theFile to choose file
	set rawData to (do shell script "mdls " & quoted form of (POSIX path of theFile) & " | sed 's| *= |=|' | grep -e\"^kMD\"")
	set theLines to paragraphs of rawData
	set {olddelims, text item delimiters} to {text item delimiters, "="}
	repeat with thisLine in theLines
		set metaData to metaData & {{(text item 1 of thisLine), (text items 2 thru -1 of thisLine as string)}}
	end repeat
	set text item delimiters to olddelims
	log metaData

So, is there a way to reference a key => value pair from this record or would I have to create a data source with columns “variables”, “values” and add rows for each new kDM identifier and its value?

I’ve created this to mine the data…

on valueFromKey(searchKey, hash)
	repeat with pair in hash
		if item 1 of pair contains the searchKey then return item 2 of pair
	end repeat
end valueFromKey

hmm - it was also possible to make a record of this values like so:


property q : "\""
	set metaDataRec to "{"
	set theFile to choose file
	set rawData to (do shell script "mdls " & quoted form of (POSIX path of theFile) & " | sed 's| *= |=|' | grep -e\"^kMD\" |sed 's|\"||g'")
	set theLines to paragraphs of rawData
	set {olddelims, text item delimiters} to {text item delimiters, "="}
	set cnt to (count of theLines)
	repeat with n from 1 to cnt
		set thisLine to item n of theLines
		set metaDataRec to metaDataRec & (text item 1 of thisLine) & ":" & q & (text items 2 thru -1 of thisLine as string) & q
		if n < cnt then
			set metaDataRec to metaDataRec & ", "
		else
			set metaDataRec to metaDataRec & "}"
		end if
	end repeat
	set metaDataRecord to (run script metaDataRec)
	-- log metaDataRecord
	set text item delimiters to olddelims

then you can ask for values of metaDataRecord like so:

set theContentType to kmditemcontenttype of metaDataRecord