Record of last saved document...

Hi there everyone,

Does anyone know if it’s possible to create a record, something like a text file, of every document saved regardless of it’s app?
Is there some sort of system event that can be captured, maybe a ‘write to HD’ event?

The ‘Documents’ section of ‘Recent Items’ of the Apple menu is getting it’s info from somewhere, can that be tapped into?

I have found this post http://bbs.macscripter.net/viewtopic.php?id=10334 which has proved useful.
I’m trying to amend this

set recent_items to (do shell script "defaults read com.apple.recentitems " & "doc" & "s | grep -v '(' | grep -v ')'")

so it returns a list of the documents along with it’s path and when it was last saved. Can anyone tell me if that is possible?

Thanks,

Nick

is this what you mean:

set search to "\"Name =\""
set recent_items to paragraphs of (do shell script "defaults  read com.apple.recentitems Documents |grep " & search & "| cut -d '\"' -f 2")

Not sure how to get path

Hi Mark,

Thanks for your reply and for the code which does what I was looking for.
Is there a date and time that can be pulled out too?

Thanks again.

Regards,

Nick

There does not seem to be.

But the List will be in the same order that the menu Recent items displays

If some one knows how to convert the Alias Data entry
for the file
example:
“<00000000 01500003 00000000 c34978e0 0000482b 00000000 008ad1c2 008ad526 0000c3f7 7d860000 00000920 fffe0000 00000000 0000ffff ffff0001 001c008a d1c2008a d1c10042 a1890042 a1880042 a1460038 f7b00038 f3a1000e 0058002b 00570053 00420034 00310045 00460045 00310039 002d0043 00390038 0034002d 00340062 00610062 002d0042 00320043 0045002d 00310041 00330044 00420041 00420034 00390031 00320039 002e0068 0074006d 006c000f 001a000c 004d0061 00630069 006e0074 006f0073 00680020 00480044 0012006e 4c696272 6172792f 4170706c 69636174 696f6e20 53757070 6f72742f 41646f62 652f4865 6c702f65 6e5f5553 2f50686f 746f7368 6f70456c 656d656e 74732f36 2e302f57 53423431 45464531 392d4339 38342d34 6261622d 42324345 2d314133 44424142 34393132 392e6874 6d6c0013 00012f00 ffff0000>”

Then maybe you could get the path and work from there??

with a heavy heart one of my secrets: :wink:

set rawData to "<00000000 01500003 00000000 c34978e0 0000482b 00000000 008ad1c2 008ad526 0000c3f7 7d860000 00000920 fffe0000 00000000 0000ffff ffff0001 001c008a d1c2008a d1c10042 a1890042 a1880042 a1460038 f7b00038 f3a1000e 0058002b 00570053 00420034 00310045 00460045 00310039 002d0043 00390038 0034002d 00340062 00610062 002d0042 00320043 0045002d 00310041 00330044 00420041 00420034 00390031 00320039 002e0068 0074006d 006c000f 001a000c 004d0061 00630069 006e0074 006f0073 00680020 00480044 0012006e 4c696272 6172792f 4170706c 69636174 696f6e20 53757070 6f72742f 41646f62 652f4865 6c702f65 6e5f5553 2f50686f 746f7368 6f70456c 656d656e 74732f36 2e302f57 53423431 45464531 392d4339 38342d34 6261622d 42324345 2d314133 44424142 34393132 392e6874 6d6c0013 00012f00 ffff0000>"
set rawData to text 2 thru -2 of rawData
set {TID, text item delimiters} to {text item delimiters, space}
set rawData to text items of rawData
set text item delimiters to TID
set thePOSIXdata to (run script "«data alis" & (rawData as text) & "»") as text
set theAlias to POSIX file thePOSIXdata as alias

I appreciate the sacrifice, thanks :slight_smile:

…But I get this error
“A unknown token can’t go here.”
And this part Highlights

run script “«data alis” & (rawData as text) & “»”

Cheers
M

Ok Figured it out, the

set {TID, text item delimiters} to {text item delimiters, space}

Is removing the spaces, but putting in a ,
I most likely can Sed the text.

Ok, Thanks Stefan for the data conversion.

This weill get the Name, Path and Last Used date, (Last Opened Date -AFAIK)

set searchName to "\"Name =\""
set searchAlias to "\"Alias =\""
set thegrepMdls to "kMDItemLastUsedDate"
set biglist to {}
set recent_items to paragraphs of (do shell script "defaults  read com.apple.recentitems Documents |grep " & searchName & "| cut -d '\"' -f 2")
set recent_items_paths to paragraphs of (do shell script "defaults  read com.apple.recentitems Documents |grep " & searchAlias)
repeat with i from 1 to number of items in recent_items_paths
	set this_item to item i of recent_items_paths
	set rawData to (do shell script "echo " & quoted form of this_item & "|sed 's/\\ //g'|sed 's/Alias=<//g'|sed 's/>;//g'")
	set thePOSIXdata to (run script "«data alis" & (rawData as text) & "»") as text
	set theAlias to POSIX path of (thePOSIXdata)
	try
		set theAliasAccess_date to text from word 3 to word -1 of (do shell script "mdls  " & quoted form of theAlias & "|grep " & thegrepMdls)
		copy ((item i of recent_items & return) & (theAlias & return) & "Last Used Date = " & theAliasAccess_date) to end of biglist
	on error
		copy ((item i of recent_items & return) & (theAlias & return) & "Last Used Date = Not Available") to end of biglist
	end try
end repeat
biglist


Its late here, so do not have time to trim this down, but it seems to work

Hi There,

Just wanted to say a big thank you to you both for your time on this it’s much appreciated.
Thanks also for the code, it’s interesting to see, especially ‘one of your secrets’ Stefan.

I’ve tried executing the code, which compiles fine, however I get an ‘Applescript Error’ that I’ve not seen before.
It says ‘Way too long, dude’. Can anyone tell me why this is happening and is there a way round it?

Regards,

Nick

Browser: Safari 419.3
Operating System: Mac OS X (10.5)

I have had that when I used a number that was to long for applescript to handle.

Are you able to see which Recent Item it gets stuck on useing the ‘Event log’ window

Hi Mark,

Thanks for your reply.

Looking at the Event Log this is the last thing it’s tried to do:-

run script "«data alis000000000414000300000000bc7b6d650000482b61730001007cd1f9007ecea30000c40e9bd4000000001111fffe5850524a58505233ffffffff0
001000c007cd1f9007c49b1007c16b8000e002a0014004800530042005f003300300039003700360063005f004300680061006c006c002d004c0
0650074000f002a0014004a006f006200730020006f006e00200050005200470059005f005000520049004d004500200046001200492f4853425
f33303739365f4c6574746572732f55736572446566696e6564466f6c646572732f33204e61746976652050616765732f4853425f333039373663
5f4368616c6c2d4c6574000013001f2f566f6c756d65732f4a6f6273206f6e20505247595f5052494d4520462d3100000902f402f46166706d0080
0404000b00240044006800a800e8012c002101350155000000000000000000000000000000000000000000000000000000000000000000000
00000000a505247595f5052494d4500000000000000000000000000000000000000000000000000144a6f6273206f6e20505247595f5052494d
45204600000000000000000000000000000000000000000000000000000000000000000000000000000000000000066e686561726e0000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020c0431302e
31332e332e343208020a0d032a0224000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000ffff0000»"

Is that any help?

Regards,

Nick

my script expects, that the raw data starts with “<”, not with spaces and “Alias”
The sed version is quite cool, but calling shell scripts in a repeat loop is quite expensive
Even with 15 items the text item delimiters version is almost half a second faster


set searchName to "\"Name =\""
set searchAlias to "\"Alias =\""
set thegrepMdls to "kMDItemLastUsedDate"
set biglist to {}
set recent_items to paragraphs of (do shell script "defaults  read com.apple.recentitems Documents |grep " & searchName & "| cut -d '\"' -f 2")
set recent_items_paths to paragraphs of (do shell script "defaults  read com.apple.recentitems Documents |grep " & searchAlias)
repeat with i from 1 to number of items in recent_items_paths
	set this_item to item i of recent_items_paths
	set {TID, text item delimiters} to {text item delimiters, "<"}
	set rawData to text item 2 of this_item
	set text item delimiters to ">"
	set rawData to text item 1 of rawData
	set text item delimiters to space
	set rawData to text items of rawData
	set text item delimiters to TID
	set thePOSIXdata to (run script "«data alis" & (rawData as text) & "»") as text
	set theAlias to POSIX path of (thePOSIXdata)
	try
		set theAliasAccess_date to text from word 3 to word -1 of (do shell script "mdls  " & quoted form of theAlias & "|grep " & thegrepMdls)
		copy ((item i of recent_items & return) & (theAlias & return) & "Last Used Date = " & theAliasAccess_date) to end of biglist
	on error
		copy ((item i of recent_items & return) & (theAlias & return) & "Last Used Date = Not Available") to end of biglist
	end try
end repeat
biglist

Hi Stefan,

Thanks for your reply and for the revised code.

When I try executing it I still get the applescript error ‘Way too long, dude’ and this part of the code is highlighted?

run script "«data alis" & (rawData as text) & "»"

Is it something I have set differently on my system, I’m running 10.4.10?

Regards,

Nick

I just tested on a 10.4.9, its defiantly a 10.4 issue…??

Yes, you’re right.
From AppleScript Release Notes

.
Bug Fixes
.
¢ Raw data literals («data …») are no longer limited to 127 bytes. [4986420]

Thanks again for your help with this guys, looks like I’ll have to upgrade.

Regards,

Nick