AlterPaste Home

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.

  1. Monitor. The app checks the clipboard for new text.
  2. 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.
  3. Detect. Each enabled rule's isMatch function runs against the text.
  4. Transform. An auto-apply transformation runs right away. Otherwise a picker offers every matching transformation.
  5. 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.
  6. 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

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

ParameterDomainReplace withComment
utm_source*organicReplace 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 examples

utm_source   the exact name
*            every query parameter
/^utm_/      every utm_ parameter
fbclid       Facebook click tracking
tag          Amazon affiliate tracking

Domain examples

*                       every site
amazon.com              Amazon and its subdomains
/(\.)?amazon\.[a-z.]+$/ Amazon sites in every country
facebook.com            Facebook only

Replacement examples

(empty)   remove the parameter
organic   replace the value with organic

Examples

With the tag and utm_source codes removed for Amazon:

Copied: https://amazon.com/product?tag=affiliate123&utm_source=email
Pasted: https://amazon.com/product

With 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=organic

History

Settings → History keeps recent copies in memory while the app is open. It is never written to disk, and it clears when you quit.

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 null

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

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.
← Back to AlterPaste · AlterPaste on iPhone