Feature Request: Option for "Write Variable to File" to not move existing file to trash

@peternlewis It would be nice to have an option in the "Write Variable to File" action to just overwrite an existing file without moving it to the trash.

I'm currently solving this by checking to see if the file exists before I overwrite it, and deleting it if it does exist. But it would be nice if I didn't have to do this.

You might wonder why I'm noticing this behavior. I'm experimenting with saving some large "state" data to disk instead of storing it in a variable, and that means I may save the data many times in a short period of time. Which clutters up the trash pretty quickly.

Thanks.

If you delete the file using the "rm" command in Terminal, I don't think it fills the Trash folder.

Same with the "Delete File" action. I'd just rather not have to do either.

Feel free to ignore this suggestion, but have you considered using an SQLite database for your state data? If you’re saving large volumes of data frequently it sounds like an ideal use case for SQLite.

You would then only have one database file and nothing going to the trash, and would also potentially benefit from being able to query the database for subsets of your data as you need it in your macro(s).

Thanks for the idea, but this isn't worth that kind of effort. Especially since I'll be sharing this with everyone, and setting up a sql database is way overkill for this.

1 Like

Don't bother checking for the file to exist, just delete it beforehand (turning off notification/abort).

I don't like allowing the Write File to delete things without you being very clear that that is your intention.

3 Likes

@DanThomas, I'm sure you know that the Delete File action will write to the Engine.log if the file does not already exist.

Is there a reason you don't want to use an Execute a Shell Script?

echo "$KMVAR_local_StateData" > "$KMVAR_local_StateDataFilePath"

Download: ReplaceFile.kmmacros (7.7 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.0 (24A335)
  • Keyboard Maestro v11.0.3

That's a cool method. Thanks for sharing.

1 Like