I have a line with text and a date inside the clipboard.
I want to add 7 days to the date that is inside the clipboard.
The problem is that I can use %ICUDateTimePlus% only for the current date, but in the line with text there can be other dates.
For example, this is the line: This is the line with a date 1983-08-07 #Week
This is the result that I would like to have after running the macro: This is the line with a date 1983-08-14 #Week
This is a screenshot of the macro that is not working:
This is the error after running the macro:
How to get the result that I would like to have after running the macro?
I don't know enough about the shell to know why your script might be failing, but if you know your dates will always follow this format, you can get the results you're looking for by slightly changing your regex to grab the date numbers, plugging them into variables, and using them in conjunction with the TIME() and "ICUDateTimeFor" token to add seven days to the date in question like this:
If, after reading the other suggestions, you still want to use a shell command, try this:
date -v+1w -j -f "%Y-%m-%d" "$KMVAR_DateOriginal" "+%Y-%m-%d"
The -v+1w tells it to add one week to the date, and the rest sets the date to whatever's in the DateOriginal Keyboard Maestro variable.
I suspect the problem with the command you tried is that it's written for GNU date instead of the BSD version that comes with the Mac. On the Mac, the -d option is used for Daylight Saving Time, not specifying the date to operate on.
Thanks for all the help, it works! Before posting this question I already searched for a solution. But found only topics that gave solutions that are not really what I was looking for. Some solutions were too advanced for me. Because this is a basic question, I hope that it can have value for basic users who are starting with KM.
This macro can be useful if you want to create recurring tasks. I'm using it in an outliner tool like Dynalist, Workflowy, OmniOutliner, Checkvist, Athens Research, Roam Research, or other outliners.
This (screenshot below) works for me, please reply if something can be done better.