Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to place recent items in a folder System
I wrote this Applescript because I wanted my recent items in a folder that I could put in the dock. I run it every five minutes via cron.

robg update: Josh has sent in the following modified AppleScript, which is a nicer implementation. Make sure to customize it for your own machine!
set workFolders to ¬
  {"Misc", "Bible Studies", "Gradient", "InterVarsity", "Missions", "Guitar Tablature"}

set daysAgo to 15
set recentItemsFolder to "Macintosh HD:Users:josh:Recent Items:"

tell application "Finder"
  move every item of folder recentItemsFolder to trash
  repeat with counter from 1 to (number of items in workFolders)
    make alias file to every file of entire contents of folder ¬
      ("Macintosh HD:Users:josh:Documents:" & (item counter of workFolders)) ¬
        whose (modification date is greater than ((current date) - daysAgo * days) ¬
      and name does not contain ".qdfm") at alias recentItemsFolder
  end repeat
end tell
[robg adds: I haven't tested this one...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[6,372 views]  

An AppleScript to place recent items in a folder | 10 comments | Create New Account
Click here to return to the 'An AppleScript to place recent items in a folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Can't get it to work
Authored by: TC!! on Feb 01, '05 11:23:21AM

I couldn't get this to work.
First I got an error because the Recent Items directory didn't exist so I created it.
Now I get this error:
"Finder got an error: Can't continue ."

Script editor highlights the following as being the cause of the error:
file nextItem_path exists
Which is inside create_links

My setup may be different from normal as I have moved my Users directory to a different partition.

Please reply as this will be very useful, I think I would adapt it to create a folder of recent apps as well.



[ Reply to This | # ]
Can't get it to work
Authored by: joshelgin on Feb 01, '05 11:37:00AM

Try this. Replace the "create_links" handler with the following:

[code]
on create_links(item_list, recentItems_folder)
repeat with counter from 1 to (number of items in item_list)
set nextItem to item counter of item_list
set nextItem_path to POSIX file nextItem
try
tell application "Finder"
if file nextItem_path exists then --Make sure the original item is still there
if (file (recentItems_folder & (name of file nextItem_path)) exists) = false then --Make sure the link does not already exist
make new alias file to nextItem_path at alias recentItems_folder with properties {name:name of file nextItem_path}
end if
end if
end tell
end try
end repeat
end create_links
[/code]

I get the "Finder cannot continue" error as well. I don't know what causes it, but it has something to do with the finder checking on a file that actually doesn't exist. It seems that it doesn't like doing it sometimes...



[ Reply to This | # ]
Tweak
Authored by: cfoster on Feb 01, '05 11:26:04AM

Replace the first line with these two to have it work for any user:

tell application "Finder" to set boot_volume to name of startup disk as text set pathToRecentItemsFolder to boot_volume & ":Users:" & (do shell script "whoami") & ":Library:Recent Items:"

[ Reply to This | # ]
Tweak
Authored by: hopper on Feb 01, '05 03:57:57PM

we're getting there, but now I get an error "the variable aliasList is not defined" in the line

repeat with counter3 from 1 to (number of items in aliasList)



[ Reply to This | # ]
Re: Tweak
Authored by: joshelgin on Feb 02, '05 12:23:03PM

Try running the script without the "remove_old" part first, to get the list of files into the folder. Then run the "remove_old" part again...



[ Reply to This | # ]
Tweak
Authored by: joshelgin on Feb 02, '05 12:25:40PM

...or move the "end try" below the "end repeat" in the "remove_old" handler.



[ Reply to This | # ]
Why?
Authored by: q-wert on Feb 02, '05 12:12:02AM

Purely out of curiosity....

I am truly curious as to why someone would want to put 'Recent Items' in the Dock. What advantage does it have over the current solution : Apple menu > Recent Items

Don't get my wrong : it's fun to know what you can do. :-)

However, the reason for this escapes me. Could someone list some advantages I have clearly missed?

The Apple > Recent Items :
- you can already configure the Apple - Recent Items menu ; already Organized (Apps & Docs). Heck, you could only put Apps or Docs if you wanted.
- it has the same accessibility : a single click - then drag/move for your selection. And both are accessible no matter what app is active.
- it spares some space on the Dock. (since the Dock already has a big job to do: quick launcher, app switcher, etc.)



[ Reply to This | # ]
Re: Why?
Authored by: joshelgin on Feb 02, '05 12:20:11PM

I think there have been studies done that show that (especially right handed) computer users spend most of the time with the mouse on the right half and bottom half of the screen. Since this is where the dock resides, it is actually faster and more convenient.

The other reason I believe it gives faster access to the files is because once I place the folder in the dock, I simply right click and the files are right above the mouse; I don't have to navigate to the sub-menu.

As for the dock having a big job...I only keep the apps I use most often down there, not every app that I have installed on my computer. I also tend to open the same documents often, so I want them in the dock with everything else.



[ Reply to This | # ]
Maybe because...
Authored by: ecco on Feb 02, '05 01:54:05PM

...I *never* use the AppleMenu.
So having the recent items in the dock is quite useful for me.
I changed the script a little bit and now it shows doc and apps in my recent items folder.



[ Reply to This | # ]
Why?
Authored by: renderhead on Mar 02, '05 11:36:46AM

The Apple menu "Recent Items" is only updated when you open a file through the Finder. It doesn't update when you open a file through an application. For example, I often open my Word documents from the "File -> Recent Files" menu in Word. When I quit Word, I no longer have access to that recent file list.

This script checks the "modified" date instead, which will update the list whenever a file is created or saved within the target directories.



[ Reply to This | # ]