4 Replies Latest reply: Nov 27, 2012 2:37 AM by abhi_apple
abhi_apple Level 1 Level 1 (0 points)

Hi Everyone,

 

Can we delete the Finder history through an Apple Script.

 

I want to delete the history at these 2 paths:

 

1) I need to clear the history under the "Recent Items" menu which comes under the Apple icon at upper left corner of our mac screen.

 

2) Secondly, I need to remove the history from the below path:

 

Finder-->Go-->Recent Folders--> Clear Menu

 

Thanks in advance for helping me out.

 

Best,

 

Abhishek

  • Jacques Rioux Level 4 Level 4 (2,505 points)

    Hi,

     

    Try this:

    -------------

    quit application "Finder"
    delay 1
    set prefFolder to path to preferences as string
    tell application "System Events"
          tell appearance preferences
                set x to {recent applications limit, recent documents limit, recent servers limit}
                set {recent applications limit, recent documents limit, recent servers limit} to {0, 0, 0}
                set {recent applications limit, recent documents limit, recent servers limit} to x
          end tell
          tell property list item "FXRecentFolders" of contents of property list file (prefFolder & "com.apple.finder.plist") to set value to {}
    end tell
    activate application "Finder"
    

     

    Cons: This script quit the Finder:

     

     

    Or this script:

    ----------------

    tell application "System Events"
          tell appearance preferences
                set x to {recent applications limit, recent documents limit, recent servers limit}
                set {recent applications limit, recent documents limit, recent servers limit} to {0, 0, 0}
                set {recent applications limit, recent documents limit, recent servers limit} to x
          end tell
          tell process "Finder"
                set frontmost to true
                click last menu item of menu of menu item -4 of menu of menu bar item 6 of menu bar 1
          end tell
    end tell
    

     

    You will need to enable access for assistive devices in the Universal Access System Preferences panel for this to work.

    Cons: Need GUI Scripting enabled and the Finder needs to be in the foreground.

  • MrHoffman Level 6 Level 6 (13,020 points)

    If this is for disk imaging (and I'm obviously making a large guess as to your overarching goal) then having a dedicated local administrator can be the handiest approach here.  That also keeps the riff-raff from viewing the shell command history, too.

  • abhi_apple Level 1 Level 1 (0 points)

    Thanks Jacques..

     

    I will check the code.

     

    Regards,

     

    Abhishek

  • abhi_apple Level 1 Level 1 (0 points)

    Thanks for your note!

     

    Regards,

     

    Abhishek