Paste clean links from clipboard

Ah yes, the paste_text action will put the new link n the clipboard. Starting with version 4.404 it should work like this:

async function someJavaScriptFunction() {
	const url = await get_clipboard_content();
	const index = url.indexOf('?');

    // If the '?' character is found, return the substring from the beginning to the position of '?'
    // Otherwise, return the original URL
    const cleanedURL = index > -1 ? url.substring(0, index) : url;
		
	
    await paste_text({text: cleanedURL, insert_by_pasting: true});
    await set_clipboard_content({content:url, format: 'NSPasteboardTypeString'});

 
    return cleanedURL;
}
3 Likes