# Show me your scripts!

**URL:** <https://community.textexpander.com/t/show-me-your-scripts/123>\
**Category:** TextExpander Talk\
**Tags:** scripting\
**Created:** [March 20, 2025, 9:16am UTC](https://community.textexpander.com/t/show-me-your-scripts/123 "2025-03-20T09:16:10Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![HaniSarji](https://sea3.discourse-cdn.com/textexpander/user_avatar/community.textexpander.com/hanisarji/32/225_2.png) [@HaniSarji](https://community.textexpander.com/u/HaniSarji)\
**Post date:** [May 11, 2025, 8:10pm UTC](https://community.textexpander.com/t/show-me-your-scripts/123/10 "2025-05-11T20:10:00Z")

</div>

> [@josh.centers](#):
>
> This is great, @HelmutHauser! I’ve added the first one to our [Community Snippets Public Group](https://snippets.textexpander.com/group/fa796ecbe167aeb836aced0a65e43b94) with the abbreviation `com.nxmon`.

I propose the following enhancement to the script, which is more flexible because it allows the user to choose the desired day of the week from a popup. So, instead of creating 7 different snippets for each day of the week, we can have just one:

```JavaScript
// 1. Map weekday names to numbers
let dayMap = {
  "Sunday": 0,
  "Monday": 1,
  "Tuesday": 2,
  "Wednesday": 3,
  "Thursday": 4,
  "Friday": 5,
  "Saturday": 6
};

// 2. Prompt the user for the desired weekday
let choice = "%fillpopup:name=Select the weekday you want to find the next date for:default=Monday:Tuesday:Wednesday:Thursday:Friday:Saturday:Sunday%";
let targetWeekday = dayMap[choice];

// 3. Calculate the next occurrence of the selected weekday
let now = new Date();
let daysAhead = (targetWeekday - now.getDay() + 7) % 7 || 7;
let nextDate = new Date(now.getTime() + daysAhead * 24 * 60 * 60 * 1000);

// 4. Format the date
let weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

let weekday = weekdays[nextDate.getDay()];
let month = months[nextDate.getMonth()];
let day = nextDate.getDate();
let year = nextDate.getFullYear();

// 5. Output example: "Tuesday (May 14, 2025)"
weekday + " (" + month + " " + day + ", " + year + ")";
%filltop%

```

This script uses the `key: value` format for redefining popups. I also mentioned this format [here](https://community.textexpander.com/t/is-there-a-more-elegant-way-to-use-an-input-field-that-only-needs-part-of-the-selection-to-be-returned/173/3). It’s a super useful approach because it lets you present user-friendly labels in the dropdown while returning clean, machine-friendly values behind the scenes.

---

_[View the full topic](https://community.textexpander.com/t/show-me-your-scripts/123)._
