Show me your scripts!

I am interested in seeing everyone’s scripts (in any supported language) they use for TextExpander.

1 Like

I start! Here is the code formy “next weekday scripts”. I often say in emails let’s meet “next Monday”, “next Tuesday”, etc. and to make it clearer I add the date. I have written a script that is doing that for me.

The shortcuts are : nxmon, nxtue, etc.

Here is one for Monday. You can easily adapt it to different weekdays. Shoutout to Doug Stephen for providing the core function (below in the code).

# AppleScript for TextExpander
# Helmut Hauser
# http://www.worksmartandberemarkable.com

# For different weekdays you simply have to change the this line
# e.g., set dateOfNextWeekday to getDateOfNextWeekWeekday(Sunday) -- Sunday
set dateOfNextWeekday to getDateOfNextWeekday(Monday) -- Monday

set myWeekDay to weekday of dateOfNextWeekday
set myMonth to month of dateOfNextWeekday
set myDay to day of dateOfNextWeekday
set myYear to year of dateOfNextWeekday

# Here we put the final output together
# if you want a different format, you will have to change this line
# simply combine variables, like myMonth or my Day), with other textpiece like ")" 
# together with &
#set fullOutput to "next " & myWeekDay & " (" & myMonth & " " & myDay & ", " & myYear & ")"
set fullOutput to "" & myWeekDay & " (" & myMonth & " " & myDay & ")"

return fullOutput
# ----------------------------------------
# subroutine from Doug Stephen
# see http://canadian-fury.com/2012/08/31/performing-fixed-point-date-arithmetic-in-textexpander-using-applescript/
# adapted by Helmut Hauser


# eneric script that allows you to get the date information of a specific upcoming weekday
# e.g., to get the date of next Monday
# getDateOfNextWeekday(Monday)
# Note that the scripts caculates the next upcoming weekday 
# If today is Monday, getDateOfNextWeekday(Monday) will return the date for Monday next week
# If today is Monday, getDateOfNextWeekday(Tuesday) will return the date of tomorrow
on getDateOfNextWeekday(nextWeekdayToFind)
	set returnDate to current date
	if returnDate's weekday is nextWeekdayToFind then return (current date) + (7 * days)
	repeat until returnDate's weekday is nextWeekdayToFind
		set returnDate to returnDate + days
	end repeat
	
	return returnDate
end getDateOfNextWeekday
#----------------------------------------











2 Likes

I also have version which returns the date within a track, the corresponding abbreviation are (nxmon, (nxtue, (nxwed, etc.

Here is the code

# AppleScript for TextExpander
# Helmut Hauser
# http://www.worksmartandberemarkable.com




# For different weekdays you simply have to change the this line
# e.g., set dateOfNextWeekday to getDateOfNextWeekWeekday(Sunday) -- Sunday
set dateOfNextWeekday to getDateOfNextWeekday(Monday) -- Monday






set myWeekDay to weekday of dateOfNextWeekday
set myMonth to month of dateOfNextWeekday
set myDay to day of dateOfNextWeekday
set myYear to year of dateOfNextWeekday


# Here we put the final output together
# if you want a different format, you will have to change this line
# simply combine variables, like myMonth or my Day), with other textpiece like ")" 
# together with &
#set fullOutput to " (" & myMonth & " " & myDay & ", " & myYear & ")"
set fullOutput to " (" & myMonth & " " & myDay & ")"


return fullOutput








# ----------------------------------------
# subroutine from Doug Stephen
# see http://canadian-fury.com/2012/08/31/performing-fixed-point-date-arithmetic-in-textexpander-using-applescript/
# adapted by Helmut Hauser


# eneric script that allows you to get the date information of a specific upcoming weekday
# e.g., to get the date of next Monday
# getDateOfNextWeekday(Monday)
# Note that the scripts caculates the next upcoming weekday 
# If today is Monday, getDateOfNextWeekday(Monday) will return the date for Monday next week
# If today is Monday, getDateOfNextWeekday(Tuesday) will return the date of tomorrow
on getDateOfNextWeekday(nextWeekdayToFind)
	set returnDate to current date
	if returnDate's weekday is nextWeekdayToFind then return (current date) + (7 * days)
	repeat until returnDate's weekday is nextWeekdayToFind
		set returnDate to returnDate + days
	end repeat
	
	return returnDate
end getDateOfNextWeekday
#----------------------------------------











3 Likes

This is great stuff @HelmutHauser! It makes me so happy to see inline comments! :smiley:

2 Likes

This is great, @HelmutHauser! I’ve added the first one to our Community Snippets Public Group with the abbreviation com.nxmon.

1 Like

Here’s the same code in JavaScript so it works outside of the Mac:

var targetWeekday = 1; // 0=Sunday, 1=Monday, ..., 6=Saturday
var now = new Date();
var daysAhead = (targetWeekday - now.getDay() + 7) % 7 || 7; // Skip to next week if today matches
var nextDate = new Date(now.setDate(now.getDate() + daysAhead));
var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekday = weekdays[nextDate.getDay()];
var month = months[nextDate.getMonth()];
var day = nextDate.getDate();
weekday + " (" + month + " " + day + ")";

1 Like

Snippet that slugify the text in the clipboard.
Example: “This is one phrase I’d like to slugify” becomes “this-is-one-phrase-id-like-to-slugify”.

var text = TextExpander.pasteboardText.toLowerCase();
text = text.replace(/[àÀáÁâÂãäÄÅåª]+/g, 'a');       // Special Characters #1
text = text.replace(/[èÈéÉêÊëË]+/g, 'e');       	// Special Characters #2
text = text.replace(/[ìÌíÍîÎïÏ]+/g, 'i');       	// Special Characters #3
text = text.replace(/[òÒóÓôÔõÕöÖº]+/g, 'o');       	// Special Characters #4
text = text.replace(/[ùÙúÚûÛüÜ]+/g, 'u');       	// Special Characters #5
text = text.replace(/[ýÝÿŸ]+/g, 'y');       		// Special Characters #6
text = text.replace(/[ñÑ]+/g, 'n');       			// Special Characters #7
text = text.replace(/[çÇ]+/g, 'c');       			// Special Characters #8
text = text.replace(/[ß]+/g, 'ss');       			// Special Characters #9
text = text.replace(/[Ææ]+/g, 'ae');       			// Special Characters #10
text = text.replace(/[Øøœ]+/g, 'oe');       		// Special Characters #11
text = text.replace(/[%]+/g, 'pct');       			// Special Characters #12
text = text.replace(/\s+/g, '-');           		// Replace spaces with -
text = text.replace(/[^\w\-]+/g, '');       		// Remove all non-word chars
text = text.replace(/\-\-+/g, '-');         		// Replace multiple - with single -
text = text.replace(/^-+/, '');             		// Trim - from start of text
text = text.replace(/-+$/, '');            		// Trim - from end of text
TextExpander.appendOutput(text);

1 Like

Thanks for sharing your script.
I don’t see how this script works. I copied the script as above into a snippet box, gave it a name and abbrev. Tried to run it and nothing happened. What am I doing wrong? Thanks for your help.

[quote=“acarter, post:6, topic:123”]
Here’s the same code in JavaScript so it works outside of the Mac:

var targetWeekday = 1; // 0=Sunday, 1=Monday, ..., 6=Saturday
var now = new Date();
var daysAhead = (targetWeekday - now.getDay() + 7) % 7 || 7; // Skip to next week if today matches
var nextDate = new Date(now.setDate(now.getDate() + daysAhead));
var weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var weekday = weekdays[nextDate.getDay()];
var month = months[nextDate.getMonth()];
var day = nextDate.getDate();
weekday + " (" + month + " " + day + ")";

[Here’s the same code in JavaScript so it works outside of the Mac:]
I am new to this scripting business. Could you describe how to make this work. I have created a snippet “com.nxtmon2” copy/pasting the Java script above and change the “Rich Text” to “java script” - now what am I missing. Thanks for your help.
Arthur

1 Like

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:

// 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. 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.

1 Like

Hi Arthur, glad to see you here! Be sure Content Type is set to JavaScript.

All the scripts I copy are in the correct format: java or apple script. Maybe you could clarify what the beginning and ending signal code should be to tell the body what format it is in. Thanks for trying to help.

Hi Arthur, I added this Snippet to the Community Snippets Public Group and confirmed it works. Search com.nextdate to see how it works!

(We are working on a much better way to share Snippets. Stay tuned!)