How to stop AppleScript application content files from appearing in "Recents" folders?

I'm a big fan of AppleScript and am currently utilising it for a range of different tasks on my computer. However, one thing I have noticed is that after I have created an Application in AppleScript, many of the content files including the main.scpt and the applet.icns files begin appearing in my "Recents" folder in Finder. This can be rather annoying as it quickly clogs up my recents folder especially if I have been working on a number of different apps.

My question is: how do I make sure that only the application itself can be viewed in the recents folder and not some of its content files as well. If so, how would I do this? Is it possible to do when creating the application itself?


Solution 1:

The following answer will add a .metadata_never_index file inside the Application folder. This will prevent indexing by Spotlight of the folder hopefully preventing it from appearing in Recents.


Here's the script. Save it to /Library/Scripts/Folder Actions Scripts/:

on adding folder items to theFolder after receiving theNewItems
    --  Called after items have been added to a folder
    --
    --  theFolder is a reference to the modified folder
    --  theNewItems is a list of references to the items added to the folder 
    repeat with myItem in theNewItems
        tell application "Finder"
            if myItem's name extension is "app" then -- make sure its an app
                set myPath to the POSIX path of myItem
                do shell script "touch " & quoted form of (myPath & ".metadata_never_index")
            end if
        end tell
    end repeat

end adding folder items to
  1. Navigate to the folder where you save your Apple Scripts

  2. Right click on that folder and select Services>Folder Actions Setup

  1. Select the script that saved and click Attach

  2. Make sure Enable Folder Actions is checked in the upper left

  3. Test.

  4. Celebrate!