Append text file without newline?

I’m trying to set up a custom action to log mileage to a text file (on Dropbox) which will then be imported to Numbers for a spreadsheet table.

I have the first action set up so it prompts and appends all the relevant info, comma-delisted as desired/required. Works great.

But when I use my “end” mileage action, the ending mileage gets appended to the text file on a new line.

Is there a way to suppress that newline addition when appending?

Appreciate this is a Drafts forum, but have you ever thought of a Google Sheets/Forms setup for mileage data capture? Yes, I know it’s Google, but if you can get over that bit, then for consistent capture/data analysis, a form linked to a sheet is an extremely simple workflow.

As the form has a distinct URL you can add it to a task manager for repeat running etc. Including array formulas in the sheet’s header rows will mean you can get calculations performed (if required) even when new rows are added via the form.

As I say, I love Drafts, but sometimes there are easier alternatives out there for certain use cases, provided you are OK with the company involved. Just a thought.

I agree with @TDK_SA90 that for something like this you might well be better off looking at how to simplify the interaction and get it directly into somewhere you might use it; thus addressing the need to import, though that could potentially be automated depending upon your avalable resources.

That being said, it could be that there’s something we’re unaware of that means a text file is the best approach. There are also other scenarios where appending in the way described is always the best approach. To that end, here’s a couple of JavaScript functions you can include via a Script step that will append the draft content to the end of the specified file. They do this by reading in any existing file content and writing back the same content with the current draft content appended directly to the end.

Here’s one for use with Dropbox as per your scenario.

appendDraftToFileDropbox("/Append Example.txt");

function appendDraftToFileDropbox(p_strFilePath)
	let fmDropbox = Dropbox.create();
	let strFileContent =;
	//If the file does not exist write the draft content, otherwise combine and overwrite
	if (strFileContent === undefined)
		fmDropbox.write(p_strFilePath, draft.content, "add", false);
		fmDropbox.write(p_strFilePath, strFileContent + draft.content, "overwrite", false);

Here’s another one for use with iCloud.

appendDraftToFile("/Append Example.txt");

function appendDraftToFile(p_strFilePath)
	let fmCloud = FileManager.createCloud();
	fmCloud.write(p_strFilePath, + draft.content);

You can adopt similar approaches for other cloud storage providers compatible with Drafts.

Hope that helps.

1 Like

I actually started out trying to do this with Apple Numbers forms on iOS (I use both the iOS and macOS versions for my spreadsheet stuff). But the iOS forms input doesn’t work with pop-up menus I’ve built (for common drives and destinations) which turned me down the Drafts route.

I also have an extensive plain-text personal database system set up, so I kinda like to develop workflows that are the least reliant on specific apps as possible.

That said, not against using Google Sheets, maybe their forms do what I need.

The drafts solution I’ve cobbled together mostly does the trick, but when it inserts a newline it creates a situation where I’d have to go back and edit each ending mileage entry. However, with some regex and Atom, this is not all that big of a deal in the long run. But obviously most ideal to avoid all that if possible.

I’ll look at Google Sheets, I have the app installed already but haven’t used it much at all.

Thank you.

Thank you! I am surprised such a convoluted workaround is necessary to avoid newlines being inserted. I come from the approach of “please do not insert any characters not explicitly requested”. Drafts is usually on that same page.

Part of my plain-text approach is because if I need to edit the file for any reason, it’s far easier to open up 1Writer and do the edits there, than it is to open up a spreadsheet app, find the mileage file, go to the cell, etc etc.

In this very specific use, I am only looking to capture the data. I have a master spreadsheet I’ll be dropping the data into (in Apple Numbers).

While I agree the direct approach can often be faster, I specifically have found manipulating text files in my already-optimized and regularly accessed plain-text personal database setup in 1Writer (and nvALT/Atom on macOS) is the fastest way to edit and browse text/data.

Drafts is more of my capture solution. And spreadsheets are great for complex number crunching, but less so for quick open/edit/capture of data on the fly.

Thank you for those scripts! I think I saw another Action using scripts that prompted with the number pad, will see if I can figure out how to meld with yours :slight_smile:

Just to add that Google Forms work fine on mobile.

To clarify, in Apple Numbers on iOS, “forms” are a feature of the actual spreadsheet document that allow for quick data entry on smaller screens.

From what I gather regarding Google Forms, I would need to set up an internet-dependent form on the Google Forms web app, which would then populate a sheet in Google Sheets after entering the data from a URL where the form resided.

If so, that’s definitely moving away from the simplicity and app-independence I am aiming for.

It’s quite a simple set up. Sounds like connectivity-dependence is the thing not to your liking which is fair enough.

Yeah I’ve used Google Forms before and collected data into a spreadsheet.

But I want to accomplish this more simply. Thanks for the suggestion.

@TDK_SA90 Did you find a solution? I’m working on a very similar project, capturing mileage using an iOS Shortcuts automation that runs when my phone connects and then disconnects from Airplay. It’s the disconnecting that’s the issue, because I can’t append without the new line entering, meaning at some point I have to go back and clear out the line breaks before I export the CSV file.

Appending will always add a line break. If you are doing this with the new shortcut actions, you could do a “Get Draft”, create append the text in Shortcuts and do an “Update Draft” which replaces contents without adding the line break.

1 Like

Awesome. And finally a good reason for me to upgrade for Pro features. Being able to log my mileage easily is more than worth the yearly subscription. Thanks!!

I saw this pop up again recently. Just thought I’d flag that if planning on putting data into a CSV file format using Drafts/Shortcuts etc., it’s possible to automatically summarise/analyse the data in that file in Google Sheets. This means that you don’t need an internet connection at the point of recording the mileage; just have an action that sends ‘created date’, ‘mileage’ to, say, a Dropbox CSV, whenever it’s convenient.

The thing that facilitates this is the IMPORTDATA function in Google Sheets. I’ve actually written this up in an example Sheet which explains in full how this works. May be of use to someone. Here’s the link.

With some additional Apps Script (don’t ask me:-)), you could even get the mileage summary automatically emailed on a periodic basis or upon sheet update.

I think you missed the piece were OP said that editing in a spreadsheet app is more painful than editing in a plain text document. Simple? Sure. And a whole of taps to get into the cell to edit. And if you want to change a few characters, good luck trying to get the cursor to the correct spot. That’s not easy even in plain text.

I’m not sure how many columns this file will be for OP, but I can say that I really do not enjoy editing spreadsheets on iOS, but i tend to have big csvs. ¯_(ツ)_/¯

You can refer to how to prevent newline addition at