Paste Custom Text action: Paste as HTML

Hello,

Is it possible for the Paste Custom Text action to support pasting as HTML?

I have some HTML snippets that I'd like to paste into Jira WYSIWYG editors with a keyboard shortcut. The Jira WYSIWYG editor understands "Apple HTML pasteboard type" pasting (type determined from Clipboard Viewer Clipboard Viewer for Mac OS X) and then renders it correctly. However with plain text or RTF from the Paste Custom Text action, the markup is pasted as text rather than the resulting HTML.

Any help much appreciated.

You can try to copy the HTML text with AppleScript to the clipboard and then with CMD + V to the current application:

-- sample HTML
set theHTML to "<a href=\"https://community.folivora.ai/t/paste-custom-text-action-paste-as-html/23676\" target=\"_blank\">Paste Custom Text action: Paste as HTML</a>"

-- copy to clipboard
Pasteboard's copyHTMLtoClipboard(theHTML)

-- paste to current application
tell application "System Events" to keystroke "v" using command down

script Pasteboard
	use framework "Foundation"
	use framework "AppKit"
	
	property NSString : a reference to current application's NSString
	property NSPasteboardTypeHTML : a reference to current application's NSPasteboardTypeHTML
	property NSPasteboardTypeString : a reference to current application's NSPasteboardTypeString
	
	on copyHTMLtoClipboard(someHTML)
		set htmlString to NSString's stringWithString:someHTML
		-- get pasteboard
		set pb to current application's NSPasteboard's generalPasteboard()
		pb's clearContents()
		-- set the first object in the clipboard
		pb's setString:htmlString forType:NSPasteboardTypeHTML
		pb's setString:htmlString forType:NSPasteboardTypeString
	end copyHTMLtoClipboard
	
end script

Tip: If the editor still recognizes plain text, then comment out this line:

pb's setString:htmlString forType:NSPasteboardTypeString

1 Like

@Dirk, many thanks for such a quick reply and a great solution!

That has worked perfectly for my use case. I've inserted that into a blocking AppleScript action with my HTML, and it's inserting correctly.

Cannot thank you enough!

Imprint | Privacy Policy