Skip to main content
guillaumef73484071
Participant
March 4, 2019
Answered

AfterEffect - Clear cache script at shutdown

  • March 4, 2019
  • 3 replies
  • 7089 views

Hello,

I am looking to start a disk cache cleanup script when closing After Effect.

The script is fully functional when I run it from the script executor.

However, when it is started at closing, I have the message displayed but nothing happens at the cache.

I think the problem is in the window that asks for confirmation before deletion (when it is started manually).

Do you have any ideas or solutions?

Here is the script (normally valid for CS6, CC) :

{

app.executeCommand(10200);

alert("Clear cache !");

}

Thank you in advance.

Have a good day.

Guillaume.

This topic has been closed for replies.
Correct answer guillaumef73484071

Hello,

Many thanks to justintaylor for his help.

I managed to do what I wanted as follows :

     {

          // After Effect - Cleaner Cache

          // Get the path to the cache folder and convert \ in \\ ;

          var CacheFilePath = app.preferences.getPrefAsString("Disk Cache Controls", "Folder 7")+"\\Adobe*";

          var FullCacheFilePath = CacheFilePath.split('\\').join("\\\\");

   

          // Delete my folder and these sub folders

          system.callSystem('cmd.exe /c "for /d %a in ("'+FullCacheFilePath+'") do rmdir "%a" /s /q"');

     }

This script was placed in the "Shutdown Script" in order to be executed at the closing of after effect (and not the closing of a project).

Warning :

Script execution preferences must be enabled.

It may happen that the Directory is not deleted because some files are used: No worry, they will be deleted at the next closing.

I remain available for advice, improvement, question or others.

3 replies

guillaumef73484071
guillaumef73484071AuthorCorrect answer
Participant
March 15, 2019

Hello,

Many thanks to justintaylor for his help.

I managed to do what I wanted as follows :

     {

          // After Effect - Cleaner Cache

          // Get the path to the cache folder and convert \ in \\ ;

          var CacheFilePath = app.preferences.getPrefAsString("Disk Cache Controls", "Folder 7")+"\\Adobe*";

          var FullCacheFilePath = CacheFilePath.split('\\').join("\\\\");

   

          // Delete my folder and these sub folders

          system.callSystem('cmd.exe /c "for /d %a in ("'+FullCacheFilePath+'") do rmdir "%a" /s /q"');

     }

This script was placed in the "Shutdown Script" in order to be executed at the closing of after effect (and not the closing of a project).

Warning :

Script execution preferences must be enabled.

It may happen that the Directory is not deleted because some files are used: No worry, they will be deleted at the next closing.

I remain available for advice, improvement, question or others.

Participant
February 26, 2024

Hello Guillaume,

do you think your last script could work on cc2024? I tried it as a shutdown script but it does not work. I guess i am not understanding the ´´´  in the last line.. Is it " ´? Regards

Justin Taylor-Hyper Brew
Community Expert
Community Expert
March 11, 2019

It appears you can't clear disk cache via scripting. You can only clear the image/undo/snapshot caches:

http://docs.aenhancers.com/general/application/?highlight=disk%20cache#app-purge

As a workaround, you could write a script that manually deletes the caches in the cache directory.

On Mac it's: /Users/[username]/Library/Caches/Adobe/After Effects

or you can find it by going to Preferences > General > Media & Disk Cache > Choose Folder

guillaumef73484071
Participant
March 12, 2019

Hello,

Thank you very much for your answer.

The function "app.executeCommand (10200)" is functional when executing the script manually.

In fact, it directly calls the "Clear cache" in preference. (See the list here for example: http://sydefxink.com/AECC2014_MenuIDs_v2_0.pdf)

What I do not explain is that the script does not work at 100% when activating via shutdown.

I have multiple users on the same machine and each user has their own cache. This saturates the machine. I need to find a way to purge the cache after the after effect closure or the user session.

If you have ideas I am listening.

Thank you.

Guillaume.

Justin Taylor-Hyper Brew
Community Expert
Community Expert
March 12, 2019

Yes, that command works with user input, selecting the OK button, but shutdown doesn't care about alerts and will just close them since it's shutting down After Effects. A lot of command IDs work this way, unfortunately. If there's not an API that does the same thing, then you have to get creative.

Only workaround that's coming to mind right now is looping through and deleting all the files in the system's cache folder with File.remove() / Folder.remove(), or executing a delete command via the system terminal per OS (rm -r on Mac or mrdir /s on PC) with system.callSystem().

NOTE: Be careful what you're deleting with this method, there is no undo option here.

Inspiring
March 5, 2019

Moved to the After Effects Scripting forum.