How to save AppleScript Editor Documents

applescript

I try to save script in front most window in AppleScript Editor to desktop as text without using GUI scripting.

tell application "AppleScript Editor" to save contents of document 1 as text in ((path to desktop) & "test.txt" as string)

Best Answer

To save it as a .scpt file for AppleScript Editor:

tell application "AppleScript Editor"
    save document 1 as "script" in file ((path to desktop as Unicode text) & "Hello.scpt")
end tell

To save as a plain .txt file, just change the middle line slightly

tell application "AppleScript Editor"
    save document 1 as "text" in file ((path to desktop as Unicode text) & "Hello.txt")
end tell