Latest in Applescript

Image credit:

AppleScripting Dates > Elapsed Time Calculator

Share
Tweet
Share
Save

Sponsored Links

Since Valentine's Day is this week, I thought I would take this opportunity to share an AppleScript I wrote to calculate how long my wife and I have been married. With this baby, I'll never be accused of forgetting how long it's been when our anniversary rolls around. The script determines the elapsed time between now (the current date and time), and a prior date and time (such as our anniversary). It then displays the result in seconds, minutes, hours, days, weeks, months and years.

Note: If you're into the whole "traditional anniversary gift" thing (I'm not), you can find a list of gift categories on Wikipedia.

Creating the Script

Note: If you have any trouble following along, you can download the complete script here.

1. Launch AppleScript Editor in /Applications/Utilities and create a new script document.

2. Insert the following code:

Some notes about this script...

* I used some of the number calculation handlers in the Essential Subroutines section of macosxautomation.com, although, I made some slight modifications to them for the script. If you're interested in learning more about AppleScript, there are some other useful handlers there, as well, and I encourage you to check them out.

* The final display dialog sets as its icon the FavoriteItemsIcon icon file, which is embedded in the CoreTypes bundle in /System/Library/CoreServices. It is, coincidentally enough, a heart.

Using the Script

To use, just run the script within AppleScript Editor, or save it as an application to be launched and run whenever you wish. First, the script asks you to enter a date and, optionally, a time.

Image

Next, the script does its calculations and displays the result. Just take a screenshot of the dialog and send it along to your significant other.

Image

Until next time, Happy Scripting and Happy Valentine's Day Week!

All products recommended by Engadget are selected by our editorial team, independent of our parent company. Some of our stories include affiliate links. If you buy something through one of these links, we may earn an affiliate commission.
Comment
Comments
Share
Tweet
Share
Save

Popular on Engadget

Drako's GTE electric supercar will be a four-motor, 1,200HP monster

Drako's GTE electric supercar will be a four-motor, 1,200HP monster

View
Nintendo says there is no Switch exchange program

Nintendo says there is no Switch exchange program

View
IKEA creates a business unit devoted to smart home tech

IKEA creates a business unit devoted to smart home tech

View
US will reportedly give Huawei another temporary reprieve

US will reportedly give Huawei another temporary reprieve

View
The next Apple Watch may come in titanium and ceramic models

The next Apple Watch may come in titanium and ceramic models

View

From around the web

Page 1Page 1ear iconeye iconFill 23text filevr