Clear recent file list in AppleScript?

I created an AppleScript for cleaning the clipboard which had this command:

tell application "System Events" to set the clipboard to ""

How would I create an AppleScript that did this with this shell script in Catalina latest version?

I tried:

do shell script "defaults delete -g NSNavRecentPlaces"

and got this error message:

error "2020-06-27 22:20:11.304 defaults[1830:54087] 
Domain (kCFPreferencesAnyApplication) not found.
Defaults have not been changed." number 1

How would I get an AppleScript to work for this sort of thing like the clipboard one I made?

Any advice appreciated on this!


In AppleScript, you do not need System Events to clear the clipboard, just use:

set the clipboard to ""

To use the above AppleScript command from Terminal, use the following command:

osascript -e 'set the clipboard to ""'

To clear the general clipboard from Terminal, not using AppleScript, use the following command:

pbcopy < /dev/null

To clear the find clipboard from Terminal, not using AppleScript, use the following command:

pbcopy -pboard find < /dev/null

That all said, there is a discrepancy between the title of your question and the AppleScript code you're wanting to run in Terminal.

If you are wanting to clear the Recent Items on the Apple menu, then the following AppleScript command will do that:

tell application "System Events" to ¬
    click menu item "Clear Menu" of ¬
        menu 1 of ¬
        menu item "Recent Items" of ¬
        menu 1 of ¬
        menu bar item "Apple" of ¬
        menu bar 1 of ¬
        application process "Finder"

To use that in Terminal:

osascript -e 'tell app "System Events" to click menu item "Clear Menu" of menu 1 of menu item "Recent Items" of menu 1 of menu bar item "Apple" of menu bar 1 of process "Finder"'