Click on a specific file from a list and open it.

I am trying to generate a list of recent docs and then click on the doc I want to open. This is what I have so far:

set olddelims to my text item delimiters
set NUM_DOCS to 8

-- now process recent docs...
set recentdocs_string to process_recentitems("doc", NUM_DOCS)
set my text item delimiters to olddelims
return recentdocs_string

on process_recentitems(itemtype, num_items)
	--first process recent items...
	set recentitems to (do shell script "defaults read " & itemtype & "s | grep -v '(' | grep -v ')'")
	set my text item delimiters to ","
	set recentitems to (text items 1 through num_items of recentitems)
	-- remove any double-quotes
	set my text item delimiters to """
	set recentitems_noquotes to {}
	repeat with the_item in recentitems
		set recentitems_noquotes to recentitems_noquotes & (text item 2 of the_item)
	end repeat
	-- now get just the itemname
	set my text item delimiters to "/"
	set recentitems_names to {}
	repeat with the_item in recentitems_noquotes
		set recentitems_names to recentitems_names & (text item -1 of the_item)
	end repeat
	set target_item to choose from list recentitems_names with prompt "Choose file to open:"
end process_recentitems

This code generates the list but when I click on the file it doesn’t open it. Any help would be appreciated. Most of this code is from another applescript and I only understand part of it. What I’m trying to do is access “Recent Items” from the Apple menu.

Is this what you want?


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

That’s perfect. Thanks alot.

this is not really a solution but a further question to jonn8.

when i tried your code, it does a wonderful job of listing the most recent items but it also picked up files that TextEdit, for example, would not be able to read. For instance, .scpt and .sit files.

is there a way to filter the most recent items and pick only certain types of files…for instance “.txt” or “.rtfd”? or would this require a differnt “do shell” script?

thanks for the info.

archseed :?:

Hi archseed,

The script I modified above will simply look at the recent items file and pull out the documents from it, not specific document types. Once a file has been chosen, it uses the command line tool “open” to open that file using the default application for the file type chosen. If you want to limit the specific file types the script returns (e.g., .txt or .rtf per you example which may open in TextEdit by default on many though not all machines), you’d need to modify the script so that the grep routine further limited the items from the recent items document to just those matching your extension criteria. Something like this (which will only work if you have at least one .rtf document in your recent items):


gee thanks, jon.

i will try your codes and will let you know how it came about.

i am always impressed by your prompt reply and seemingly endless resource of scripting prowess. and, you’re always very helpful…something all of us in the scripting community is proud and happy to have.

archseed :smiley:


here’s a quick update.

tried your script and it worked like a charm.

will try to study from your codes for my own learning process. may be i can come up with a little more useful modifications. who knows?

many thanks once more.

archseed :smiley: with :idea:

Jonn et al.

Would it be possible to sort the selection list according to last date openened
of the recent apps/documents…?

Eelco Houwink