AlterPaste
on the Mac
A menu bar app that rewrites what you copy with your own JavaScript rules and takes tracking codes off links.
Also see AlterPaste on iPhone.
How it works
Copy as usual. If a rule fits, pick a transformation or let auto-apply run. Then paste.
- Monitor. The app checks the clipboard for new text.
- Skip. Concealed, transient, and auto-generated copies are ignored, so passwords from a password manager are left alone. Brief clipboard restores from dictation and password apps are ignored for a set number of seconds.
- Detect. Each enabled rule's
isMatchfunction runs against the text. - Transform. An auto-apply transformation runs right away. Otherwise a picker offers every matching transformation.
- Clean links. If tracking removal is on, tracking codes are removed as the last step. This applies when the copied text is a single link, so a sentence that contains a link is left alone.
- Replace. The result replaces the clipboard. The copy is added to History when Save copies is on.
The picker can take keyboard shortcuts. Turn them on in Settings → General. Then a number key picks that option, Return picks the first, Escape cancels, and the picker takes keyboard focus.
Settings
General
- Launch at login
- Monitoring on or off, and its keyboard shortcut
- Show a notification when a transformation applies
- Remove tracking codes from URLs
- Picker keyboard shortcuts, and how long an unused picker stays open
- Ignore clipboard restores, from 1 to 5 seconds
- Tracking lists from alterpaste.com: turn a list on, choose sites for lists grouped by site, view a list's codes, download a list again, and refresh the catalog
Rules
Create, edit, turn on or off, and delete JavaScript rules. The editor tests your detection and transform functions before you save. A JSON rule with Minify and Prettify comes with the app, turned off. See Writing rules.
Tracking
A table of tracking codes, with a URL tester that shows the result as you type. See Tracking codes.
History
Recent copies, kept in memory. See History.
Help and About
Help is a short summary with a link to this page. About shows the version.
Tracking codes
Tracking removal is the last step, after any transformation. Turn it on in Settings → General, and edit your codes in Settings → Tracking. Lists you turn on apply first, then your own rows.
The table
| Parameter | Domain | Replace with | Comment |
|---|---|---|---|
utm_source | * | organic | Replace UTM source with organic |
/^utm_/ | facebook.com | (empty) | Remove all UTM params from Facebook |
tag | /amazon\.com$/ | (empty) | Remove Amazon affiliate tags |
fbclid | * | (empty) | Remove Facebook click tracking |
- Parameter: an exact name such as
utm_source,*for every query parameter, or a regex such as/^utm_/. - Domain:
*for every site, a host such asamazon.com(its subdomains included), or a regex. - Replace with: empty removes the parameter. A value replaces it. For
*, the value becomes the new query string. - Comment: your own description.
Parameter examples
utm_source the exact name
* every query parameter
/^utm_/ every utm_ parameter
fbclid Facebook click tracking
tag Amazon affiliate trackingDomain examples
* every site
amazon.com Amazon and its subdomains
/(\.)?amazon\.[a-z.]+$/ Amazon sites in every country
facebook.com Facebook onlyReplacement examples
(empty) remove the parameter
organic replace the value with organicExamples
With the tag and utm_source codes removed for Amazon:
Copied: https://amazon.com/product?tag=affiliate123&utm_source=email
Pasted: https://amazon.com/productWith a row that replaces utm_source with organic, and one that removes ref:
Copied: https://shop.com/item?utm_source=paid&ref=12345
Pasted: https://shop.com/item?utm_source=organicHistory
Settings → History keeps recent copies in memory while the app is open. It is never written to disk, and it clears when you quit.
- Save copies is off by default. Turn it on to start a list. It records only while monitoring is on.
- Keep up to 100 copies. The default is 25.
- Filter: Keep and Skip each take a
/pattern/, the same as tracking codes. A copy is saved when Keep matches the original or the changed text and Skip matches neither. An empty Keep keeps everything, an empty Skip skips nothing, and Skip wins when both match. - When AlterPaste changed a copy, its row shows Original and Modified. Each line has its own copy button, and each row has a delete button.
- Show History in the menu bar lists the last 10 copies. Click a line to copy it again.
Writing rules
A rule is two JavaScript functions. The clipboard text is the content argument. Create rules in Settings → Rules.
Detection
isMatch returns true when the rule applies.
function isMatch(content) {
try {
JSON.parse(content.trim());
return true;
} catch {
return false;
}
}Transform
transform returns the new text. Return null to leave the clipboard as it is.
function transform(content) {
try {
return JSON.stringify(JSON.parse(content));
} catch {
return null;
}
}A smaller example
function isMatch(content) {
return content.includes("@");
}
function transform(content) {
return content.toUpperCase();
}The AlterPaste API
console.log("Debug message"); // Writes to Show Logs
AlterPaste.logMessage("Custom log message"); // Writes to Show Logs
AlterPaste.showAlert("Important message"); // Shows a native alert
AlterPaste.unshorten("https://bit.ly/abc123"); // Follows redirects, returns the final URL or nullunshorten makes a network request to the URL you pass it. Nothing else in a rule can reach the network.
Environment
Rules run in JavaScriptCore, not a browser. String, Array, Object, RegExp, JSON, Date, and Math work. URL, fetch, XMLHttpRequest, document, window, and localStorage don't. Parse URLs with RegExp or string methods:
const match = content.match(/^https?:\/\/([^\/]+)/);
const domain = match ? match[1] : null;Rules are code you write, and they run against everything you copy. Treat them like any script on your Mac.
Logs
Show Logs, in the menu bar menu, streams console.log output and script errors, with search, a source filter, and auto-scroll. Turn on Include debug to also see AlterPaste's own pipeline messages.
Tracking lists
AlterPaste can download tracking lists from alterpaste.com, so you don't have to collect codes yourself. Turn lists on in Settings → General. Some lists are grouped by site, and you can choose which sites to use.
- On launch, if there was no successful check this calendar month, the app checks for new versions of the catalog and of every list you turned on.
- A failed check keeps the last good copy.
- Only the catalog and the list files are downloaded. What you copy is never sent anywhere.
Troubleshooting
- No transformations appear.
- Check that monitoring is on, with no red circle on the menu bar icon, and that the rule is turned on. Test its detection function in the rule editor. If a script error is likely, open Show Logs.
- A transformation doesn't work.
- Check the transform function's syntax and that it returns text. Try the JSON rule that comes with the app first.
- A link still has tracking codes.
- Check that Remove tracking codes from URLs is on in Settings → General, and that the copied text is only the link. Paste the link into the tester in Settings → Tracking to see which codes apply.