(* Copyright Mark Hunte 2006.Info for this script can be found here. http://www.macosxhints.com/article.php?story=20060403083841944*) global text_returned, exits, this_item_name on run set exits to false tell application "Script Editor" activate tell document (frontmost) set the_script_text to contents as Unicode text my _set() if this_item_name contains "Untitled" then tell application "Script Editor" set choose_name to display dialog "Choose name" default answer "" buttons {"cancel", "Ok"} default button 2 copy the result as list to {text_returned, button_pressed} if button_pressed is equal to "OK" then set this_item_name to text_returned as string set name of window 1 to this_item_name --my _names(this_item_name) else if button_pressed is equal to "Cancel" then set exits to true end if end tell else my _names(this_item_name) end if end tell my setComm(this_item_name, the_script_text) end tell end run on _names(this_item_name) tell application "Script Editor" set choose_name to display dialog "Set New Name to save as New file" & return & " Or click No to overwrite .aslt file" default answer this_item_name buttons {"Cancel", "No", "Yes"} default button 2 copy the result as list to {text_returned, button_pressed} if button_pressed is equal to "Yes" then set text_returned to text_returned as string set name of window 1 to text_returned else if button_pressed is equal to "Cancel" then set exits to true end if end tell end _names on _set() tell application "Script Editor" set this_item_name to name of window 1 as string set AppleScript's text item delimiters to {"."} set line_start to text item 1 of this_item_name set AppleScript's text item delimiters to "" set this_item_name to line_start as string end tell end _set on setComm(this_item_name, the_script_text) if exits is false then tell application "Finder" set thePath to do shell script "echo " & quoted form of the_script_text & " > ~/Documents/AppleScripts/" & quoted form of text_returned & ".aslt" do shell script "touch -r " & "~/Documents/AppleScripts/" & quoted form of text_returned & ".aslt ~/Documents/AppleScripts/" --update modification timeof folder AppleScript so it jumps to the top. set new_file to POSIX path of ":Macintosh HD/Users/Documents/AppleScripts/" & text_returned & ".aslt" end tell end if end setComm