Saving text file to Obsidian

I’m trying to save a Text using Save File. I wasn’t sure how to create a File that I could use in Save File, so I tried Append to Text File. However, I could never get the parameters correct, and kept getting errors about the File Path needed to be contained within the directory. If I try using the Text directly in Save File, that doesn’t work either (probably because I think it needs to be a File type, not Text). Right now, I’m stuck. I don’t see any useful examples. Although the Photo example is helpful, it doesn’t help with my situation. Thanks.

Just passing the result of a Text action as File parameter should suffice:

Shortcuts passes results between actions as files already, or turns them into files on-the-fly. So the Text result will be treated as a file. This also works for Dictionaries and other types:

Does that help?

Yes, that really helps a lot. I did not realize that Shortcuts passed Text or Dictionaries as a File. I kept trying to use Append Text to File to create a File for the Save File action. I guess it defaults to writing it in the Shortcuts folder on iCloud. And then I need to delete that Appended File after running Save File so it doesn’t hang around. I didn’t know that I could just use Text as a File for Save File.

Also, it’s nice to know this works for Dictionary too since that might be an easy way to create a JSON file. Actually, I had a JSON object as my Text, and it’s a bit more involved so it might not be so easy to use a Dictionary in this case.

Including these examples under Save File would help to complement the Photo example.

1 Like

I’ll do that, and your questions help me find the weak spots in the docs, it’s really good, keep 'em coming! :+1:t3:

1 Like

For some reason, AFO quits unexpectedly when I try to Save File from the Text. I tried it several times. Maybe I need to reboot or something.

I just saw the exceptions in Sentry, just can’t tell whose it is. :wink: Are you on macOS 14.4.0 by any chance? I only see one anonymous origin (user) with several crashes.

Please try a reboot if you have a minute. I’ll look into it, but I’d like to know if the issue persists.

Yes, I’m on macOS Sonoma 14.4. I kept trying several combinations and each crashed. Sorry for extra reports. They’re probably all the same. I will try rebooting and see if that clears everything up.

Okay, I rebooted macOS, and tried it again. The first 2 times I got an error something like “Unable to communicate with helper application”. When I tried it the 2nd (and 3rd) time, then AFO crashed and probably sent you more reports.

Also, it’s not clear what the file name will be when you use Text as the File. Then, I thought maybe I could save Text into a Variable, and use that variable (thinking it might be used as the file name, which might be better than something like Text.txt).

I don’t see how to specify what the file name should be for the new file that’s saved. So I added a Rename File action to change my variable to the name that I wanted (along with the correct extension). It might be something like .json (or .canvas, in my case).

BTW, when creating a new Effort in Obsidian, I’m generating an initial Obsidian Canvas using the JSON Canvas spec, which contains some starter text, file, and link nodes with a few edges (arrow connections).

I see them. I have a working theory about the cause, at the moment I try to reproduce the crashes on my test systems.

Also, it’s not clear what the file name will be when you use Text as the File. […] I don’t see how to specify what the file name should be for the new file that’s saved.

You can’t specify it right now because I didn’t think about creating entirely new files, I was just thinking about storing already named files from camera or other apps. But there’s already a ticket as part of 2024.2, “Make file names configurable”. :slight_smile:

BTW, when creating a new Effort in Obsidian, I’m generating an initial Obsidian Canvas using the JSON Canvas spec, which contains some starter text, file, and link nodes with a few edges (arrow connections).

Holy crap, that’s a brilliant idea! :100: Once that’s working, that’d be a good tutorial post or video, I think.

So far, you seem to be the only customer for whom Save File crashes. Would it be possible for you to isolate the problem, and share that isolated workflow with me, @doug78645?

Okay, I stripped it down to a few basic scenarios and I still get the error “Couldn’t communicate with a help application” on the Save File action. I assume that means the Actions for Obsidian app that provides the app intents for the Shortcut actions.

I tried several variations: creating a Text, Get File for an existing text file, Append File to save the Text in the iCloud Shortcuts folder. The latter did append my Text to the Appended File before Save failed. I included screenshots for all of them. Usually I get this error and the shortcut terminates, and occasionally AFO crashes. BTW, it does work fine with a Take Photo as you show in your example.

I’m starting to think that maybe I need to go to JavaScript or Shell Script if I want to do this in Shortcuts using AFO Save File. However, it might be simpler to do it in a Templater script in Obsidian. I will explore those options while you’re investigating what’s going on with Save File.

image

Thank you, Doug. I still can’t reproduce it on my end. I’m also on macOS 14.4, using the same AFO build as you, but I get no crashes.

The only difference I see when looking at the crash reports is that I’m on Apple Silicon and you’re on an Intel machine. Still, that should not make a difference. But it gives me something to work with in terms of research.

However, I’m afraid I don’t have access to an Intel Mac on 14.4 at the moment, so a solution might take a while.