Sometimes it’s useful to put up a dialog with some info from a running script, and copy and paste some of that into the script, to compare the output with the code.
When doing this, small icons that appear to have “CR” inside of them appear in the editor at the end of every pasted line.
These little things make reading the text difficult and require manual editing one-by-one to get rid of. I’d much rather that they weren’t pasted in the first place.
I’ve been through the menus and preferences, and searched the in-app Help, and the forum in various ways, but can’t find a way to prevent these small icons from being pasted along with the text.
Is there some way to prevent these things from being pasted into the editor? Thanks.
Unfortunately, a recompile does not make them go away:
In SD, run a script that puts up a dialog with info
Copy text from the dialog
Paste the copied text into a comment block in SD: the CR icons are pasted at the ends of the pasted lines of text
Recompile: the CR icons remain
And because none of the pasted text is valid code, pasting it outside of a comment block and recompiling just causes a compile error, and the CR icons are unaffected and reman.
I run this script, and copy the text from the dialog and paste it inside a comment block in a Script Debugger script. (below)
With Show Invisibles turned off, when I paste it, I do not see the CR icon, but it then appears when the script is compiled.
With Show Invisibles turned on, when I paste it I see the CR icons for the Return lines and the LF icon for those lines. If I turn Show Invisibles off, the CR icons persist.
This seems to be a bug.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set textForDialog to "First linefeed" & linefeed
set textForDialog to textForDialog & "Second linefeed" & linefeed & linefeed
set textForDialog to textForDialog & return
set textForDialog to textForDialog & "First return" & return
set textForDialog to textForDialog & "Second return" & return & return
--display dialog
set buttonList to {¬
("Cancel"), ¬
("Okay") ¬
}
set DialogReply to display dialog ("Copy text paste into Script Debugger window inside a comment block") ¬
with title ("testing") ¬
default answer textForDialog ¬
buttons buttonList ¬
default button 2 ¬
cancel button 1 ¬
(*
First linefeed
Second linefeed
First return
Second return
*)
No – this is a deliberate decision not to mess with what’s on the clipboard inside comments. Here’s a simple example of where it could be problematic:
set theData to read theFile as «class utf8»
(*
--For testing:
set theData to "First Last Age
John Citizen 33
Jane Doe 56"
*)
-- do stuff with theData
Suppose the text in the file is return-delimited, and you want to test the code with a sample instead of the full file. If the returns were auto-converted, the pasted sample data would no longer reflect the contents of the file, and you could end up wondering why your sample works but not the full file.
It’s simple enough to script the change for a selection:
tell application id "com.latenightsw.ScriptDebugger8" -- Script Debugger 8.app
set theSel to selection of document 1 as text
set theSel to paragraphs of theSel
set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {linefeed}}
set theSel to theSel as text
set AppleScript's text item delimiters to saveTID
set selection of document 1 to theSel
end tell
And perhaps I should have mentioned that I’m copying text displayed in a dialog, not text entered in a dialog, as in the attached script and screenshots.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set foo to "foo"
set bar to "bar"
set baz to "baz"
display dialog "Hello world" & return & foo & return & bar & return & baz & return
(*
*)