Search code examples
macosshortcut

Save text to file shortcut Monterey


I try to create a shortcut for macOS Monterey to export data from Tim (a time tracker) and save that data to a file.

I am able to do the first step (export data), but I have no idea how to do the second step (put the text in a file).

One way could be to use a shell script to export the data:

shortcut app paste input to shell

But this gives me an almost empty file:

$ cat tim.txt
Save text to file%          

There must be a [better] way to save the data to a text file.

When I try to debug the first step, I get the correct output:

debug information look ok

How can I save the text to a file (overwrite the file or create the file if it does not exist.)


Solution

  • After some digging I've found that it is more straightforward than I thought.

    save file in shortcut app

    There seems to be a bug (or a IMO bad behaviour) in the shortcuts app, the suffix of the file is always .txt, but I prefer .json, so I need a third step to rename the file.

    The problem I had was to change the directory to the desired output and use a relative filename from there.