Scripting Script Debugger?

I have 35 scripts that all call a routine in the same script library. I was asked to change the name of the script library, easy enough. But that meant that all 35 scripts that refer to that script library had to be opened, and then updated with the new name, and then recompiled, and then saved, and then closed. I thought maybe I could script Script Debugger itself to do this search-and-replace job, a file at a time. But I couldn’t figure out how to do it. I am using Script Debugger 6 and it does not appear that Find and Replace are part of its AppleScript dictionary. If Script Debugger 7 can handle such a thing I would upgrade right away!

I had some other ideas, such as opening up each script, grabbing the text of the script, and putting the text into BBEdit, which I can do a search and replace with via AppleScript, and then bringing the text back to Script Debugger, and then recompiling… but that seemed a little messy. Any other ideas?

Welcome, Christian. Here’s a basic script to get you started:

on open fileList
	repeat with aFile in fileList
		tell application id "com.latenightsw.ScriptDebugger7" -- Script
			set thedoc to open aFile
			tell thedoc
				set theContents to source text
				set source text to my modifySource(theContents)
				close saving yes
			end tell
		end tell
	end repeat
end open

on modifySource(theContents)
	-- do your modifications to theContents here
	return theContents
end modifySource

You just need to modify the modifySource() handler to make the changes to your scripts. You can do that with text item delimiters, BBEdit, AppleScriptObjC, or whatever takes your fancy. For example:

on modifySource(theContents)
	set theContents to current application's NSString's stringWithString:theContents
	set theContents to theContents's stringByReplacingOccurrencesOfString:"blah blah" withString:"boo hoo" -- modify to suit
	return theContents as text
end modifySource