Create draft to log info that are date and time specific

#1

Hi! I’m a soccer coach and I also attend Physical therapy on a weekly basis. I need to keep track of when I have both, including the date, time, location, and duration.

I want to create 2 draft lists to keep track, but I’d prefer not to have to type out the info each time. I’m sure this is fairly simple, but can anyone point me in the right direction?

Thank you!

0 Likes

#2

That’s quite an open ended question, so I’ve broken it down into som separate areas and made a few suggestions that will hopefully help you clarify your own requirements and point you towards the Drafts functionality and maybe some examples that will help you develop what you are after.

Event Type

You could either build two different actions for this, or you could popup a prompt and use it to choose which option to record. Whilst there are other options that could also be had allowing reuse and single source, that’s probably a bit of a step too far at this stage.

Assuming you want to output to a draft in Drafts (other options discussed below), has a unique ID, known as a UUID. You would associate the appropriate ID to your options or actions as appropriate to open and or append/prepend to the draft content.

Date & Time

There are various ways to insert and format dates and times. A quick search for time in the action directory provides a number of options you could peruse and reuse.

Location

You could type in the location each time via a prompt, or perhaps build a prompt to give you a list to choose from. Drafts does also allow you to pick up the last modified date for a draft (latitude and longitude), so you could use that, or you could jump out into Shortcuts for example and have that grab you a current address.

If the location was in a calendar event, then Drafts could read that data in and use it.

Duration

This once again could be typed, selected via a prompt or taken from a calendar entry. You could also take the current time, round it off, calculate the difference to the start time you noted earlier and have the action calculate the duration for you.

Output Format

There are many ways this data could be laid out in a Draft. You could have a single line log entry that’s set out for reading, or put things into a CSV record on the line.

You could have each entry on separate lines with headers on each line.

You could have sections where you have some sort of heading (e.g. in Markdown), and the details in some format underneath.

You could even forego having it in Drafts to an extent and automatically append/prepend to a file in say Dropbox or iCloud.

Hope that helps

1 Like

#3

Thank you! I am going to look into this. Not 100% sure if I know how to do a lot of what you said yet, but I can probably figure it out. Do you think this is better served as a shortcut contributing to a google sheet or something like that? Thank you!

0 Likes

#4

That all depends.

In terms of building it, what are you most comfortable with, and what do you want the final result to look like?

In terms of what it looks like and where to store it, that comes down to what are you actually going to use the data for and what’s the easiest way to access and use the data.

0 Likes

#5

I’m definitely not super comfortable with either yet, but still learning.

The coaching info needs to be copied into a text message to log my hours with my boss.

The physical therapy info is just used to compare to their record when I make a payment. I don’t know if that helps…

0 Likes

#6

The text message one I don’t see a driver for to put anywhere at all (!) unless you intend to refer back to it outside of your messages or say aggregate the figures or something else.

Again with the physio record. If it is just a lookup anything would suffice, but if you want to do more, that would potentially guide you towards other suited options.

Consider your purpose/goals for this, what you need to do with the data now, and what you might want to do with it in the future. Until you do that, you haven’t really got a direction to set off in. :man_shrugging:t2:

0 Likes

#7

This all makes sense. Is there a way to pull the same text “Flash Practice” populate the date automatically, have a choice of duration and locations.

So eventually it reads: “Flash Practice on March 26, 2019 at 7-8:30pm at Burr”

And then just generate a new line each practice.

0 Likes

#8

Yes.

As above, there are many examples of working with dates and times that you can pick out of the Actions Directory and reuse.

Whenever you want to select something you can use a prompt.

In fact there are lots of examples you can reuse in there; plus various examples via this forum.

The following links will hopefully give you a head start in looking at the sorts of areas ai mentioned previously.

Try building up your text and action step by step, and if you get stuck with a particular part, share how far you have got and I’m sure we’ll all be able to help you take it a bit further.

Hope that helps.

0 Likes

#9

Thank you so much. Let me play around with this and I will report back. Thank you!!

0 Likes

#10

Okay, so i think understand how to build the prompt to choose between the Practice/Game. But now I don’t understand how to take the result of the prompt and make it text within the draft. So I’ve tried using the insert text action after and manually type in [[prompt_button]], but that genuinely just displays that verbatim, so that can’t be it. Thank you again for all the help, really enjoying learning this!

0 Likes

#11

Can you share what you have so far? That way we can take a look at debugging what is going on. Otherwise we’ll be guessing and it could take a lot longer to get to the bottom of it.

0 Likes

#13

Not sure if this is the correct way to share, but here it goes:

drafts5://action?data=%7B%22uuid%22:%22C08CCE73-48E8-4E3B-9230-A857095B2D70%22,%22steps%22:%5B%7B%22platforms%22:3,%22data%22:%7B%22script%22:%22%5C/%5C/%20Prompt%20example%5Cn%5C/%5C/%20Using%20Select%20%5Cn%5Cnvar%20p%20%3D%20Prompt.create();%5Cnp.title%20%3D%20%5C%22Select%20Prompt%20Example%5C%22;%5Cnp.message%20%3D%20%5C%22Demonstrates%20options%20for%20single%20and%20multi-option%20select%20in%20prompts.%5C%22;%5Cn%5Cnvar%20options%20%3D%20%5B%5C%22Practice%5C%22,%20%5C%22Game%5C%22%5D;%5Cnvar%20selectedOptions%20%3D%20%5B%5C%22Second%5C%22%5D;%5Cn%5Cn%5C/%5C/%20single%20selection%5Cnp.addSelect(%5C%22s1%5C%22,%20%5C%22Select%20one…%5C%22,%20options,%20selectedOptions,%20false);%5Cn%5Cnp.addButton(%5C%22OK%5C%22);%5Cn%5Cnif%20(p.show())%20%7B%5Cn%5Ctvar%20s%20%3D%20%5C%22Selected:%20%5C%22%20+%20p.fieldValues%5B%5C%22s1%5C%22%5D%20+%20%5C%22%5C%5Cn%5C%5Cn%5C%22;%5Cn%5Cts%20+%3D%20%5C%22Multi-Select:%20%5C%22%20+%20p.fieldValues%5B%5C%22s2%5C%22%5D%20+%20%5C%22%5C%5Cn%5C%22;%5Cn%5Ctalert(s);%5Cn%7D%22%7D,%22type%22:%22script%22,%22isEnabled%22:true,%22uuid%22:%22C62BC474-D26C-4FA5-B9C9-E2FBD4137F2C%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22%5B%5BPrompt_Button%5D%5D%22%7D,%22type%22:%22insertText%22,%22isEnabled%22:true,%22uuid%22:%22AF7CA9FA-8BC5-4AF7-B415-FE66AE1A6A59%22%7D%5D,%22backingPlatforms%22:3,%22shortName%22:%22%22,%22shouldConfirm%22:false,%22disposition%22:3,%22keyCommand%22:%7B%22optionKey%22:false,%22input%22:%22%22,%22controlKey%22:false,%22commandKey%22:false,%22type%22:%22action%22,%22discoverabilityTitle%22:%22Select%20Prompt%22,%22shiftKey%22:false%7D,%22logLevel%22:2,%22groupDisposition%22:0,%22notificationType%22:2,%22tintColor%22:%22none%22,%22actionDescription%22:%22Displays%20prompt%20with%20several%20types%20of%20date%20picker.%22,%22keyUseIcon%22:false,%22icon%22:%22sim-card-alert%22,%22visibility%22:2,%22backingIsSeparator%22:false,%22groupUUID%22:%2278BABB67-8339-48EF-88C3-8E053FCB05F5%22,%22assignTags%22:%5B%5D,%22name%22:%22Select%20Prompt%22%7D

0 Likes

#14

Unfortunately I get an import error when copying and trying to launch that URL.

If you scroll down in your action, there’s an option to share your action to the Action directory. There’s an option there not to publicly list it in the directory, just host it in the directory.

Sharing in this way via the directory seems to be the easiest and most reliable way to share actions.

This should give you a nice (short) URL, that you can post and will then hopefully allow us to load and take a look at it.

0 Likes

#15

Thank you! Maybe this is better?

https://actions.getdrafts.com/a/1VM

I used the Select Prompt example to start fyi.

0 Likes

#16

It looks like you are pulling bits in from a few places, so instead I’ve taken your first step and changed it a bit to do all of what I think you were trying to accomplish.

The modified script is below and I’ve jotted a few notes below.

Hope that helps.

let p = Prompt.create();
p.title = "Select Prompt Example";
p.message = "Demonstrates options for single and multi-option select in prompts.";

let availableOptions = ["Practice", "Game"];
let selectedOptions = ["Practice"];

// single selection
p.addSelect("s1", "Select one...", availableOptions, selectedOptions, false);

p.addButton("OK");

if (p.show())
{
	editor.setSelectedText(p.fieldValues["s1"] + "\n\n");
	let selRange = editor.getSelectedRange();
	editor.setSelectedRange(selRange[0] + selRange[1], 0);
}
  • The default selection didn’t default select any of the available options. I’ve changed that.
  • I’ve removed the alert as I think it should be clear as is, and note that since you were not using multi select, part of that original alert would never populate.
  • I’ve replaced the insert text step with direct interaction with the editor in the script. This means just the one step is required. It does jump to the end of the inserted text. If you are not using the prompt action, then you would have to specify a Draft template explicitly to use in the insert text action. Note also that options are not buttons (so even if it had ‘worked’, you would have got OK each time) and I can’t recall for definite, but they may be case sensitive … so probably good practice to always use lower case.
0 Likes

#17

OMG this is so much better. How did you learn to script like this? I definitely want to learn that. I am going to keep building, would you mind if I post if there’s more issues as it’s goes along? Thank you again for all the help!

0 Likes

#18

How do you now add the date in? I went to add it as a separate action but it comes up 2 lines below it.

0 Likes

#19

There are many ways to include a date, at least several places to include it and many formats to specify the output as.

This is an updated example that uses the built in Drafts date template tag and a strftime (Google it :wink:) format string to output in a particular format. As such it is just utilising the information in the links that I posted above; so hopefully it should be stuff you’ve at least glanced over before.

let p = Prompt.create();
p.title = "Select Prompt Example";
p.message = "Demonstrates options for single and multi-option select in prompts.";

let availableOptions = ["Practice", "Game"];
let selectedOptions = ["Practice"];

// single selection
p.addSelect("s1", "Select one...", availableOptions, selectedOptions, false);

p.addButton("OK");

if (p.show())
{
let strNewContent = p.fieldValues["s1"] + " [[date|%d %b %Y]]\n\n"
	editor.setSelectedText(draft.processTemplate(strNewContent));
	let selRange = editor.getSelectedRange();
	editor.setSelectedRange(selRange[0] + selRange[1], 0);
}

For me, I’ve been writing code for almost 40 years. I taught myself from a book as a child when we got a microcomputer at home. I taught myself one of the early versions of JavaScript at university … again, from a book; but it has moved on a lot and I’m not yet fully versed in all of the revisions. However, the information is more readily available today than ever, so it is just a case of reading documentation and examples, practicing and perseverance. In terms of posting and seeking more assistance, that’s one of the foundations of this forum and I’m sure that there are many people here that are happy to help you along the way.

1 Like

#20

Thank you so much. I’m gonna look into all of this. I really appreciate all the help!

0 Likes