How to stop `Write Text to File` trashing the file

I am using Write Text to File action in a macro, to replace a file with new text.

The issue is that I use this macro a lot and really dislike how every time I do it, it will put the previous file that existed into trash. Is it possible to somehow overwrite this behavior and cleanly replace the file with new contents?

How my macro looks:

14

Hey @nikivi,

Just add a Delete file action anywhere before the Write file one with that same file path:

image

1 Like

Hey Nikita,

If you really want to overwrite the file, you can do something like this.

-Chris


Write Clipboard to File -- AppleScript Version.kmmacros (7.3 KB)

1 Like

Hey Guys,

The macro above requires that all the directories in the path to the target file already exist.

This one will create them if necessary:

Write UTF-8 Text to File using AppleScriptObjC v1.10

Both are fully UTF-8 compatible.

-Chris

2 Likes