I have a script that uses 1Writer to prepend some text to a diary.txt file that lives on DropBox so it is available to all my devices. Sometimes, if the file was updated elsewhere, it hasn’t yet synced by the time the Shortcut asks 1Writer to save to the file, and I end up with conflicted copies.
Is there some way I can tell the Shortcut to wait until the file is present, or else keep checking for, say a minute, before it writes to the file.
There may be times when my iPhone is offline or otherwise unable to sync the diary.txt file, in which case I don’t mind dealing with the conflicted copy later by hand.
Thanks
Jeremy
There is a wait action in Shortcuts that I think would have to be the basis for this.
You can’t really just ‘wait until’, as it might not exist to be synced or have been able to have been synced,
You could try reading for it every say 10 seconds until it is there, or you have done it 6 times, and then continue.
But what if it is an old version that has synced? That then gives you other conflict challenges.
If you are having sync issues like this, perhaps consider compiling a number of separate time stamped entries that you later merge. That should get around your sync issues I think.
I do something similar, but my 1Writer script/action actually sends the text to Shortcuts, and uses the Dropbox actions in Shortcuts to update the .txt file:
- Draft content in 1Writer
- Use 1Writer action/script to sent the contents to Shortcuts
- Shortcuts action prepends .txt file on Dropbox
I’ve never had these automations ask me to save the file, but I have had conflicted copies I’ve had to resolve (mostly due to Dropbox constantly crashing on macOS).
I built this as a way to use Shortcuts for appending the files, but have access to all the editing tools and a comfortable composing environment in 1Writer.
This is a completely different approach and I need to give it some thought. My feeling is that when I first started doing this, Shortcuts couldn’t prepend to a file, but maybe I am misremembering.
I’m not even using the newest version of Shortcuts, being on iOS 12 still. But it for sure can do append or prepend on text files in Dropbox or iCloud Drive.
Can you share the steps of your current workflow in more detail? Including the 1Writer script. Curious to see how you’re currently implementing things.
I’ve never shared a Shortcut before. What’s the best way to do that? Screenshots from my iPhone?
In essence, I set the destination file in a dictionary. Then ask for text input, preloading the contents of the clipboard.
Then prepend the current date to the input text
Then urlencode the text and the file path, as defined in the Dictionary
Then do an x-callback to onewriter with prepend?path= urlencodedpath&text=urlencodedtexttoappend
I was just looking for the description of the steps, but there are ways to share Shortcuts. I think via the Share menu. You have to then share the link, which is shared via iCloud, and then others can install — and you can get a preview of the steps before installing, without actually having to install.
And screenshots work too.
From your original post, sounds like your method shouldn’t cause conflicted copies any more than my method. However, I am confused when you mention “wait until the file is present” — it sounds like you are writing to a file that is always present, so why would the Shortcut need to wait for the file to be present?
Do you mean to say “wait until the file isn’t in use or being modified elsewhere”?
I meant that there is a perceptible delay between 1Writer opening and the DropBox sync making the file available on the iPhone.
The reason I think this is the root of the problem is that I most often get a conflicted copy when I have changed the diary.md file on my desktop machine and then go to use the automated posting on the iPhone. But I do need to do some proper troubleshooting.
OK, so you mean the normal delay of 1Writer launching, then syncing, then opening the desired file.
So are you modifying the diary.md file on the iPhone very soon after having modified it on the desktop computer? Syncs seem to happen pretty quickly, and in my experience well before I’d have time to grab my phone, unlock, launch a Shortcut, type, etc.
Sounds like maybe there is a slowdown somewhere as far as the desktop file syncing the file from local to remote.
I pretty much only see these sorts of things happen (resulting in conflicted copies) when I discover Dropbox on the desktop has crashed, and therefore has not been keeping things in sync and I am unknowingly altering files only locally on the desktop.
The time it takes for your script to execute seems like plenty enough time for the desktop to sync local changes to the remote servers.
I tested this specifically yesterday. Edited diary.md on the desktop at 18:02. Ran the shortcut later that night from the phone without first opening 1Writer or Dropbox and at 22:34 it created a conflicted copy. Ran the same shortcut again a minute or so later and it went to the correct diary.md file.
Maybe this is something to do with background activity in either 1Writer or DropBox. Background app refresh is off for DropBox because I do most of my work on DropBox at the desktop. No point in enabling it for this one use case, I don’t think. Easier to program a delay or simply delay myself, although I am also completely open to alternative approaches.
Syncing relies on background processes to keep things “in sync”.
Well, I did suggest an alternative approach earlier…
I do notice with my setup that it does take 1Writer a few seconds to sync with Dropbox after launch, and 1Writer does not have the ability to enable background app refresh, so I think this may be the culprit.
Sounds like the shortcut is working so efficiently that it edits the local diary.md file before 1Writer does its launch sync with Dropbox.
That is exactly it. And now that I know, I know to open 1Writer and wait a little bit before running the Shortcut.