Scripting Debugger

I’m trying to write a simple applet that when I drop a scptd file on it will duplicate it and rename for versioning purposes

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

on open of fileList
	--	Executed when files are dropped on the script
	repeat with aFile in fileList
		tell application id "com.latenightsw.ScriptDebugger7" -- Script Debugger.app
			set thedoc to open aFile
			tell thedoc
				set theBuildNumber to get build number
				set theName to get name
				set theBackUp to duplicate thedoc to (path to desktop folder) with properties {name:theName & "_" & theBuildNumber}
			end tell
		end tell
	end repeat
	
end open

I don’t think duplicate works the way intended here.

Try something like this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

on open fileList
   --   Executed when files are dropped on the script
   repeat with aFile in fileList
      tell application "Script Debugger" -- Script Debugger.app
         set thedoc to open aFile
         tell thedoc
            set theName to get name
            set theBuildNumber to get build number
            if theBuildNumber is missing value then
               set the build number to 1
               set theBuildNumber to 1
            end if
            set AppleScript's text item delimiters to {"."}
            set newName to text items of theName
            if the (count of newName) > 1 then
               set item -2 of newName to item -2 of newName & "_" & theBuildNumber
               set newName to theName as text
            else
               set newName to theName & "_" & theBuildNumber
            end if
            
            set myPath to (path to desktop folder) as text
            set newPath to (myPath) & newName
            save thedoc in newPath
         end tell
      end tell
   end repeat
   tell application "Finder" to reveal item newPath
   
end open

(Note, it would be easier to use Shane’s filemanagerlib library to handle the name and path manipulation, if you’re interested, lemme know)