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)
  • What is the question - what exactly are you trying to save? What is GUI Scripting - isn't this AppkeScript?
    – mmmmmm
    Mar 11, 2013 at 15:06
  • This is a great question. Due to the nature of what applescript does, I didn't have much hope for finding out how to save as script as both text and script without all the dialogue work involved.
    – Mockman
    Aug 24, 2018 at 11:51

1 Answer 1


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
  • Thanks. There is just one problem. I want that it saves it to desktop AND keeps original file open. Now it immediately opens new file.
    – Johnnie
    Mar 11, 2013 at 15:16
  • If I understand your problem correctly, you will need to save this script as an application. Hit cmd + S, and make sure the format is Application
    – Josh Hunt
    Mar 11, 2013 at 15:43
  • I'm creating this new script which i run from FastScripts: When i hit cmd+s, FastScripts runs script which first saves frontmost script in AppleScript Editor the usual way and then it saves copy of it as .txt or .applescript so Spotlight can search it.
    – Johnnie
    Mar 11, 2013 at 18:31
  • In the modern world, it's 'Application "Script Editor"', and to get the resulting text file to belong to Script Editor (rather than TextEdit), it should have an extension of '.applescript'. 'Unicode' is likely redundant. This is great as I've been trying to save snippets of code so that when I solve some problem I can easily refer back to my solution should I encounter a similar problem in the future. But manually saving the files is a chore because of the dropdown. Thanks.
    – Mockman
    Aug 24, 2018 at 12:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .