Append text file without newline?

actions

#1

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?


#2

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.


#3

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 = fmDropbox.read(p_strFilePath);
	//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);
	}
	else
	{
		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, fmCloud.read(p_strFilePath) + draft.content);
}

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

Hope that helps.


#4

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.


#5

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:


#6

Just to add that Google Forms work fine on mobile.


#7

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.


#8

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


#9

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.