TextExpander Current Week

I’m working in TextExpander and want to be able to create a snippet that lists the current week, Monday thru Friday.

For example, for this week, it would be Oct. 29-Nov. 2, 2018.

The kicker is that I’d like to be able to invoke this any day in the week, but it would still give Monday’s date as the start date.

Any idea how I might write that in TextExpander?

set theDate to (current date)
set theStartDate to theDate
repeat until weekday of theStartDate = Monday
	set theStartDate to theStartDate - 1 * days
end repeat
set theEndDate to theDate
repeat until weekday of theEndDate = Friday
	set theEndDate to theEndDate + 1 * days
end repeat
set theDate to (date string of theStartDate) & " - " & (date string of theEndDate)

results in:
Monday, 29 October 2018 - Friday, 2 November 2018

Which is a bit more extensive than you asked, but it is a start :slightly_smiling_face:

1 Like

Depending on whether you want to use it on iOS as well, you might want to write it in JavaScript which works on both platforms, instead of AppleScript. Brett Terpstra has a JS library and examples here that you could probably adapt easily:

http://brettterpstra.com/share/te-snippets/index.php?group=Next%20X&prefix=nd

1 Like

Is there a way to list all 5 days? Like so…

Monday, August 30, 2021
Tuesday, August 31, 2021
Wednesday, September 01, 2021
Thursday, September 02, 2021
Friday, September 03, 2021