Generate Alt Text with TextExpander


I came across AltText.AI on Appsumo and it looked like a nice tool to help with generating Alt text for images. They have integrations with a bunch of different solutions including WordPress. However I didn’t want to install a plugin just for generating alt text.

Instead, I created a TextExpander snippet that allows me to make use of their API and generate alt text on the fly only when I needed it.

Note: You shouldn't rely soley on the AI generator for your Alt text. Only as a starting point.

This solution uses an AppleScript, this means the solution only works for people on a Mac.


1. Get your API key

Make sure you are signed in to your account. Once logged in, you can get your API key from here.

A screenshot of the account page

2. Installing dependancies

The TextExpander script relies on two dependancies – Homebrew and jq.


In your terminal, run this command to install:


        ruby -e "$(curl -fsSL" < /dev/null 2> /dev/null


Once homebrew is installed. You can install jq with the command:


        brew install jq

3. The snippet

Add a new TextExpander snippet and set the content type to applescript.

Set your apiKey and replace {{image url}} and {{keywords}} with TextExpander fill ins.


        set apiKey to "XXXXXXXXXXXXX"
set imageUrl to "{{image url}}"
set keywordsString to "{{keywords}}"

set AppleScript's text item delimiters to ","
set tagsList to text items of keywordsString
set AppleScript's text item delimiters to {""}

set tagsJSON to "\"tags\": ["
repeat with i from 1 to count of tagsList
	set thisTag to item i of tagsList
	set tagsJSON to tagsJSON & " \"" & thisTag & "\""
	if i is not equal to (count of tagsList) then
		set tagsJSON to tagsJSON & ","
	end if
end repeat
set tagsJSON to tagsJSON & " ], "

set overwriteJSON to "\"overwrite\": true"
set jsonData to "{ \"image\": { \"url\": \"" & imageUrl & "\", " & tagsJSON & overwriteJSON & " } }"
set curlCommand to "curl -X POST '' -H 'X-API-Key: " & apiKey & "' -H 'Content-Type: application/json' -d '" & jsonData & "'"

	set response to do shell script curlCommand
	set altText to do shell script "echo " & quoted form of response & " | /opt/homebrew/bin/jq -r '.alt_text'"
	return altText
on error errText
	return "Error: " & errText
end try

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.


🔒I won't send you spam, I promise