File information

Hi,
Not sure if any one can help, im trying to create a script that will tell me when a file was last opened or modified. I know how to find this information using Terminal but i was wondering if there was a way that apple script with or with out a hint of shell script could do it.

The file im trying to find the info on is a pref file which is changed every time the application is opened and i wanted to get a report on the useage of this pref file (last opened or last modified)

Any ideas would be a great help.

Cheers

MD

Model: MacBook Pro
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

set _file to choose file
set _mod to modification date of (info for _file)

Hi Major,

one solution is to read spotlight metadata

set inputFile to (choose file)
set Nm to name of (info for inputFile)
set {ModDate, LastUsedDate} to paragraphs of (do shell script "mdls " & quoted form of POSIX path of inputFile & " | grep 'kMDItemFSContentChangeDate\\|kMDItemLastUsedDate' | awk '/ = / {print $3,$4}'")
display dialog Nm & return & return & "Modification date : " & ModDate & return & "Last opened : " & LastUsedDate

LOL, damn it Stefan you and Adam and your love affair with mdls.

Just kidding :smiley:

James you are a diamond thank you.

:smiley:

But it is very effective :wink:

Hi Stefan,

I’ve been looking for information on MDLS and came across this post which I’ve found very useful.

Please can you tell me if there is an easy way to extract the info below from a jpeg file or would it require the shell script amending to extract all the relevant info? Also is it possible to write this information or can it only be read?

Here’s the info list:-

kMDItemAttributeChangeDate = 2005-05-13 01:23:36 +0200
kMDItemBitsPerSample = 32
kMDItemColorSpace = “RGB”
kMDItemContentCreationDate = 2003-04-04 20:33:26 +0200
kMDItemContentModificationDate = 2003-04-04 20:33:26 +0200
kMDItemContentType = “public.jpeg”
kMDItemContentTypeTree = (“public.jpeg”, “public.image”, “public.data”, “public.item”, “public.content”)
kMDItemDisplayName = “0,1020,255663,00.jpg”
kMDItemFSContentChangeDate = 2003-04-04 20:33:26 +0200
kMDItemFSCreationDate = 2003-04-04 20:33:26 +0200
kMDItemFSCreatorCode = 0
kMDItemFSFinderFlags = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSLabel = 0
kMDItemFSName = “0,1020,255663,00.jpg”
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 34890
kMDItemFSTypeCode = 0
kMDItemHasAlphaChannel = 0
kMDItemID = 189700
kMDItemKind = “JPEG-Bild”
kMDItemLastUsedDate = 2003-04-04 20:33:26 +0200
kMDItemPixelHeight = 420
kMDItemPixelWidth = 317
kMDItemProfileName = “sRGB IEC61966-2.1”
kMDItemResolutionHeightDPI = 72
kMDItemResolutionWidthDPI = 72
kMDItemUsedDates = (2003-04-04 20:33:26 +0200)

Thanks in advance,

Nick

Hi,

first, writing parameters is not possible with mdls.
You can also get some EXIF informations with Image Events.app.
Do you need all parameters?

Hi Stefan,
Thanks for your reply.

The information I was looking to extract is:-
Height
Width
ColorSpace
Resolution Height
Resolution Width
Modification Date
Creation Date
Alpha Channel
Profile Name

Thanks again,

Nick

here an example with Image Events, but it doesn’t provide the EXIF modification date.
Maybe the Finder modification date is sufficient

set i to choose file
set mDate to modification date of (info for i as alias)
tell application "Image Events"
	launch
	open (i as alias)
	tell image 1
		set {width, height} to dimensions
		set res to resolution
		set cs to color space as string
		set pr to name of embedded profile
		set alpha to value of metadata tag "hasAlpha"
		set cDate to value of metadata tag "creation"
	end tell
	close image 1
end tell

or a way to filter the data with mdls, you get only the lines with your desired parameters, the values can be easily
extracted with AppleScript’s text item delimiters

set inputFile to quoted form of POSIX path of (choose file)
set ColorSpace to paragraphs of (do shell script "mdls " & inputFile & " | awk '/kMDItemPixelHeight/||/kMDItemPixelWidth/||/kMDItemColorSpace/||/kMDItemResolutionHeightDPI/||/kMDItemResolutionWidthDPI/||/kMDItemContentModificationDate/||/kMDItemFSCreationDate /||/kMDItemHasAlphaChannel/||/kMDItemProfileNameImage/'")

Thanks for the reply Stefan and for the code.
I’ve had a play and can get the info I require. :slight_smile:
The Image Events variation produced one or two strange results to start with but now’s it ok.
I think I may use the shell script version and extract the info from the result.

Thanks once again,

Nick

Yes, I forgot to launch Image Events explicitly,
then it works reliably

Rereading this thread just now, I realized that along the line, piping to grep was used to find a particular file attribute. That’s not necessary: mdls can do it:

display dialog (paragraph -1 of (do shell script "mdls  -name 'kMDItemAttributeChangeDate' " & quoted form of POSIX path of ((path to preferences folder from user domain as text) & "com.apple.scripteditor.plist")))