AS + BBedit, Cannot paste into dialog

Hi all,

I’m updating an old script that gets run from the BBedit script menu. I set a global from the text entered into an AS generated dialog box. This script has been running flawlessly for years until I up dated my OS from 120.5 to 10.10.5.

I also updated my BBedit to 1o.5.9.

Anyway, In the below script I can paste or type into the dialog if the script is run from the Script Editor but when I run the script from BBedit’s script menu, pasting is disabled but typing still works.

It seems BBedit thinks I have a secured dialog, like a password box or something.

Does anyone know why it’s doing this?

tell application "BBEdit"
	
	-- initial dialog box to get user requested product
	set theUniqueName to the text returned of (display dialog "Enter a unique identifier (name or number) of the product you would like to delete" default answer "")
	
end tell

AppleScript: 2.4
Browser: Firefox 52.0
Operating System: Mac OS X (10.10)

I made a little progress through searching and found I could paste into the dialog if I went to the finder first. Does anyone know why this change in BBedit?

tell application "Finder"
	-- initial dialog box to get user requested product
	set theUniqueName to the text returned of (display dialog "Enter a unique identifier (name or number) of the product you would like to delete" default answer "")
end tell

tell application "BBEdit"
	
	set errorTotals to 0 as number
	
	repeat with i in (get every text document)
		tell i's text
			
			set tagLength to 41 + 1
			set colorCodeLength to 8
			set specialClassesLength to 2
			set thumbsStart to "<thumbs>"
			set thumbsFinish to "</thumbs>"
			set headlineColors to "headlineColors"
			set subheadlineColors to "subheadlineColors"
			set legalColors to "legalColors"
			set specialClasses to "specialClasses"
			set msg to ""
			set msg1 to ""
			set msg2 to ""
			set msg3 to ""
			set msg4 to ""
			set msg1a to ""
			set msg2a to ""
			set msg3a to ""
			set msg4a to ""
			set totalProducts to 0
			set chk to 0
			set theText to ""
			
			set startTitle to ""
			set endTitle to ""
			set tempTitle to ""
			set tempTitleStrg to ""
			
			
			
			--get name of this particular template xml
			
			
			select character (9) of line 3
			set startTitle to characterOffset of selection
			set endTitle to startTitle + 30
			select (characters startTitle thru endTitle)
			copy selection to tempTitle
			set tempTitleStrg to (tempTitle as string)
			--display alert ("this is my test alert" & tempTitleStrg)
			
			
			find theUniqueName options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
			
			-- puts line where cursor sits into productLineCount
			copy the startLine of selection to productLineCount
			
			--find the line that the thumbs tag is on
			find thumbsStart options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
			copy the startLine of selection to thumbsStartCount
			
			find thumbsFinish options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
			copy the startLine of selection to thumbsFinishCount
			
			if (productLineCount is less than or equal to thumbsStartCount) or (productLineCount ≥ thumbsFinishCount) then
				set errorTotals to ((errorTotals) + 1)
				--display alert "Another Error total =" & errorTotals
				
				
			else
				set totalProducts to (thumbsFinishCount - thumbsStartCount - 1)
				
				
				
				
				
				
				copy the startLine of selection to currLine
				
				--COUNT NUMBER OF PIPE CHARACTERS IN SPECIAL CLASSES LINE HERE
				set theText to (the line currLine as string)
				--set search delimiters then reset when done
				set astid to AppleScript's text item delimiters
				set AppleScript's text item delimiters to "|"
				set pipeCount to (count theText's text items) - 1
				set AppleScript's text item delimiters to astid
				
				
				
				
				-- here is where deletions work is done below
				
				-- and subtract it from the thumbs line
				set productNumber to productLineCount - thumbsStartCount
				set productColor to productNumber - 1
				-----------------------------------------------
				--Delete the entire line that the product is on
				set deleteProductLine to line productLineCount
				delete every character of deleteProductLine
				-------------------------------------------------
				--LINE COUNT 1
				--find the text color tag and get its line number and set var lineCount1
				find headlineColors options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
				copy the startLine of selection to lineCount1
				
				--select first char of chosen product color
				select character (productColor * colorCodeLength + tagLength) of line lineCount1 --? append 'of text'?
				set startMark to characterOffset of selection
				
				-- and find next pipe char and extend selection
				set targetColor to find "[|]" options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:true} with extend selection
				
				set endMark to characterOffset of targetColor's found object
				select (characters startMark thru endMark)
				set text of selection to ""
				-----------------------------------------------
				--LINE COUNT 2
				--find the text color tag and get its line number and set var lineCount2
				find subheadlineColors options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
				copy the startLine of selection to lineCount2
				
				--select first char of chosen product color
				select character (productColor * colorCodeLength + tagLength) of line lineCount2
				set startMark to characterOffset of selection
				
				-- and find next pipe char and extend selection
				set targetColor to find "[|]" options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:true} with extend selection
				set endMark to characterOffset of targetColor's found object
				select (characters startMark thru endMark)
				set text of selection to ""
				-----------------------------------------------
				--LINE COUNT 3
				--find the text color tag and get its line number and set var lineCount3
				find legalColors options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
				copy the startLine of selection to lineCount3
				
				--select first char of chosen product color
				select character (productColor * colorCodeLength + tagLength) of line lineCount3
				set startMark to characterOffset of selection
				
				-- and find next pipe char and extend selection
				set targetColor to find "[|]" options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:true} with extend selection
				set endMark to characterOffset of targetColor's found object
				select (characters startMark thru endMark)
				set text of selection to ""
				-----------------------------------------------
				--LINE COUNT 4
				
				--find the text color tag and get its line number and set var lineCount4
				find specialClasses options {search mode:text, starting at top:true, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
				copy the startLine of selection to lineCount4
				
				
				--TEST COMMENT BELOW OUT
				--set i to replace_chars(i, "gradient", "%") of me
				
				
				-------------------------------------------------
				
				--select first char of chosen product color
				select character (productColor * specialClassesLength + tagLength) of line lineCount4
				set startMark to characterOffset of selection
				
				-- and find next pipe char and extend selection
				set targetColor to find "[|]" options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:true} with extend selection
				set endMark to characterOffset of targetColor's found object
				select (characters startMark thru endMark)
				set text of selection to ""
				
				--TEST COMMENT BELOW OUT
				--set i to replace_chars(i, "%", "gradient") of me
				
				
				--end if
			end if
			
			
		end tell
	end repeat
	
	display alert ("DONE!  Total Templates with Missing Products/Errors:" & errorTotals)
	
end tell

on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	--set the item_list to every text item of this_text
	set the item_list to this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list --as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars


--if (contents of line 1 contains "; This ") and (contents of line 2 = "") then
--delete text of lines 1 thru 2
--end if

I don’t, but I can tell you the same problem happens under 10.12.4 with BBEdit 11.6.4. I suggest you report it to the BBEdit people.

Meanwhile there’s another workaround that might be even more convenient, which is put what’s on the clipboard in the dialog as it appears. Something like this:

set theClip to the clipboard
if length of theClip > 100 then set theClip to "" -- avoid nonsense

tell application "BBEdit"
	-- initial dialog box to get user requested product
	set theUniqueName to the text returned of (display dialog "Enter a unique identifier (name or number) of the product you would like to delete" default answer theClip)
end tell

Just change the 100 to something likely to rule out invalid identifiers.

Thanks Shane,

I sent a bug report to BareBones.

Here is the reply I got back from BareBones: