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 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
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?
The information I was looking to extract is:-
Height
Width
ColorSpace
Resolution Height
Resolution Width
Modification Date
Creation Date
Alpha Channel
Profile Name
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.
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.
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")))