I am using many images in the macros to click on etc. I keep my images in one folder. Commonly in the process of editing or changes in the software the images get changed and updated, but the old images not used anymore still stay in the folder.
Is there a way to find out which images are not used anymore / linked to my macro library and delete them?
First, if you already know the name of the file you want to check, just enter the filename into the search box of the KM Editor. This will show any macro that contains that string. Of course, it's possible to have a KM macro that reads image files without having the name of the file encoded into the macro, so this won't work in all cases. For example:
The above action will read all files in a specific folder, and there's no way to know just by searching for the name whether the file is "still in use." I do this in some macros, so searching for a file by name isn't sufficient in my case. Maybe for you it's just fine. And it's possible that someone has written a macro that extracts all the hardcoded filenames out of your KM file where all macros are stored. But even that macro won't catch all cases for the reason I give above.
Second, you can get an idea of which files are unused by opening a Terminal window, setting your directory to any specific folder you like, and executing the following command in it:
ls -lu
That command will show you all the files in that folder sorted by the time each file was last accessed. If you see a file that's three years old, that means nothing has accessed it in 3+ years, and that probably means it's no longer being accessed by any KM macro (or any app.)
Those are my ideas. There may be other people who provide other ideas.
It's going to be difficult to be 100% accurate because you don't have to use a literal file path to reference an image -- you could build one with tokens, for example. So better to err on the side of caution and move the files you think are unused to another folder.
This script will let you pick your image folder, pick (or create) an unused images folder, and then check the name of each file in your images folder to see if it appears in your KM macros plist file -- if it doesn't it will move the file to your "unused" folder.
It is not restricted to image-related actions -- if the file's name appears anywhere in any of your macros it will be considered "used" and not moved.
tell application "Finder"
set fileList to every file of (choose folder with prompt "Choose your image folder")
set unusedFolder to (choose folder with prompt "Choose a folder to move unused images to")
end tell
tell application "Keyboard Maestro"
repeat with eachFile in fileList
set fileName to name of eachFile
if (count of (get every macro whose xml contains fileName)) = 0 then
tell application "Finder" to move eachFile to unusedFolder
end if
end repeat
end tell