Mac keyboard shortcut to compute future date?

I am looking for the easier way to compute a future date.


My present technique uses an Excel spreadsheet.  In this spreadsheet I place a date in a particular cell.  In the next cell I insert the desired number of days.  The spreadsheet then computes the dates before and after the starting date.


I have the spreadsheet stored as a template.  Pulling down the File menu and opening a new template takes too much time.  I would like to create a keyboard shortcut that opens the template from the keyboard.


Or could I write an Apple script to do the same computation without going through Excel?  That is, could I write a script that I could summon with a keyboard shortcut?


TIA

Mac mini, macOS 12.6

Posted on Oct 13, 2022 11:54 AM

Reply
4 replies

Nov 18, 2022 9:21 AM in response to R_55a

Here are some AppleScript date manipulations with variable usage:


set start_date to date ("Nov 18, 2022") as text
set days_increment to 2

-- using UNIX date cmd, get future date based on preceding variables
-- strftime codes for date/time: https://pubs.opengroup.org/onlinepubs/007908799/xsh/strftime.html

set future_date to (do shell script "date -j -v+" & days_increment & "d -f '%A, %B %d, %Y at %X %p' " & start_date's quoted form & " +\"%A, %B %d, %Y at %X %p\" ")

-- using UNIX date cmd, get date two days from today expressed in AS date format
set future_date to (do shell script "date -j -v+2d +\"%A, %B %d, %Y at %X %p\"")

set x to short date string of date ("Nov 18, 2022" as string) as text
set y to 2 as integer
-- date ("11/18/22") + (2 * days)
set future_date to (date x) + (y * days)

date "Sunday, November 20, 2022 at 12:00:00 AM"


More information on AppleScript date/time manipulation can be found here.

Nov 18, 2022 7:40 AM in response to Niel

Is there a way to save such a script with variables? I drafted the script with "x" where the date will go and "y" for the number of days to be inserted. Script Editor reported that "x" and "y" are invalid for the script.


I would like to develop a script or a formula that I can call into existence with a simple keystroke and then enter the values directly without having to re-type the script each time.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mac keyboard shortcut to compute future date?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.