Interesting. I have copy/paste a lot of scripts from other Discourse forums, and have never noticed this – never had an issue. Then I realized I am always pasting into an app that is expecting plain text.
I just tested pasting into Evernote and Outlook 2011, and in both cases the script was not pasted correctly.
BUT, when I did a “Paste & Match Style”, the script pasted correctly into both.
Thanks to a great little app named Script Debugger (ever hear of it?), I can easily discover the classes put on the clipboard:
set clipRec to the clipboard as record
shows this:
The problem is the «class HTML» class.
Thanks to Shane for some really cool code:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for pasteboard
### SHANE'S CODE ###
set pb to current application's NSPasteboard's generalPasteboard()
-- read as html
set htmlText to (pb's stringForType:"public.html") as text
I can get the actual HTML text from the encoded «class HTML» class.
I have to say it is shocking! It is very verbose, may worse than the HTML code that Microsoft Word produces. I would post it here, but it is too long. Just run the above script after a copy of script from a script block somewhere in this forum, and you will see the results. As you know, HTML ignores CR and LF, and needs <BR>
for line breaks. I didn’t see any in the HTML text. Or, it needs to be put in a block using <pre>
tags. Didn’t see any of these either.
###The Workaround
Use “Paste & Match Style” in rich text apps.
OR, use this simple script (enhance as you see fit):
set scriptStr to the clipboard as text
set the clipboard to scriptStr as text
###The Fix
I’ll report this in the Discourse forum (meta.discourse.org), and see if they are aware of it, and if so, have any fixes/suggestions.