I was trying to make this macro: 1) type a date (formart: m/d) in a prompt user input 2) find out the date which is one day ahead of the date I just typed in the prompt 3) insert the calculated date to text by pasting.
I now from reading the articles and wiki how to do that based on the current date, yet I'm lost totally in doing that based on a specific date I can type in. I tried to search the forum but didn't find a solution. Can anybody help? Many thanks!
It's much more complicated to calculate the difference between dates than you think.
Date Calculate or
calculate between dates you will get some topics:
Thanks for the confirmation.
I generally prefer AppleScript over Shell Script, but in this case I like the Shell Script because:
Does not embed the KM Variables in the script
Much more concise at 2 lines
Is easier to modify to change date formats
I'm not sure I follow you here. The Shell Script has a default date format of the ISO 8601 standard (international), so should be acceptable to most. If the macro builder wants to use a different format, that's easy enough to change in the scri…
A Typed String example to calculate dates ahead of today and before today. Inspired by Typinator’s
dayDelta and @peternlewis’ Calculation macro.
today+20d → Date 20 days ahead
today+3w → Date 3 weeks ahead
today+9m → Date 9 months ahead
today-3w → Date 3 weeks ago
You can change the trigger word and customize the date format in the macro.
Date format syntax
Update (2016-10-18 19:42 Z):
Date token now composed of variables (→ date format …
Thank you suliveevil. I've read the articles you kindly attached in your reply. Sadly, I still don't find the exact thing I'm look for: calculate date based on any specific date from my input.
See this Alfred Date Calculator workflow then you will know it's very complicated.
If you don't wanna start from scratch，you can search for an online date calculator to do the same thing.
Alright. Let me simply switch to another solution . Thank you anyway.
It doesn't have to be. Every date calculator need not be a general purpose calculator that handles every edge case.
Don't give up so easily.
Let's take another look at your requirements and see if we can find a solution for your specific use case.
type a date (formart: m/d) in a prompt user input 2) find out the date which is one day ahead of the date I just typed in the prompt 3) insert the calculated date to text by pasting.
That should be easy enough.
Actually, I already had a macro that does most of what you want.
I've adjusted it to use your date format. IAC, it should be enough for you to use and adapt to your specific needs.
Let us know if this works for you, or you have further questions about your OP.
: 2019-03-01 20:03 GMT-6 UPDATED
Just updated the macro to:
Change output date format to match input format: M/D
Actually paste the calculated date.
MACRO: Date Calculator Custom [Reusable Action]
~~~ VER: 2.1.1 2019-03-01 ~~~
Date Calculator Custom [Reusable Action].kmmacros (13 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
Provide a Reusable, Configurable, Action to Calculate Dates
While KM provides extensive handling of dates using the ICU tokens & functions, it is very laborous to write a macro which calculates a new date from a date other than the current date.
The Action in this macro presents an alternative to using KM ICU tokens.
It provides one KM Action, a Shell Script with a Bash date command, to accomplishes this with only 5 lines, and yet is very configurable.
It only requires two inputs, which the macro author can enter as KM Variable Tokens in the Execute Shell Script Action Input area, which are Parameters for the script Standard In (stdin):
Adjust by amount (in days, +/-)
By Default, the script uses this data, which can be easily overridden:
Adjust By Units: Days
Date Input Format: M/D/Y
Date Output Format: M/D/Y
Override these by adding Parameters to the Script Input area.
If you don't like the defaults, you can easily change the defaults in the script.
macOS 10.10+ (Yosemite)
However, it has been tested ONLY in KM 8.2.2 with macOS 10.12.6
How To Use
As a Demo
Just Trigger this macro.
Enter the Base Date and Offset
As a Reusable Action
Save the Execute Shell Script Action somewhere for easy reuse
(choose one of these:)
I recommend the KMFAM Macro System by
Setup as a Sub-Macro, which can be called using an Execute Macro Action
Paste the Script Parameters as Parameters to the Execute Macro Action
Store in a "template" macro where you can copy/paste into new Macros
Carefully review the Release Notes and the Macro Actions
Make sure you understand what the Macro will do.
You are responsible for running the Macro, not me. ??
Assign a Trigger to this maro..
Move this macro to a Macro Group that is only Active when you need this Macro.
ENABLE this Macro.
REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
(all shown in the magenta color)
Prompt for User Input
You can change the defaults for BaseDate and AdjustBy (which MUST include the sign), but do NOT change the Units.
Thank you for both your encouragement and macro, Michael! I've already embedded it into my workflow and your macro modified for me is also a great example to build something upon it by my own.