View Full Version : Applescript file duplicate help

Nov 1, 2009, 09:09 PM
I have a script that works but was wondering if I made it incorrect or if it could be improved upon. here is the script and what it does. Simply creates a folder on the current users desktop and places a file named story into it from the folder "test".

-- create a file in Textedit named "Story"
set meow to "Woof Woof"
set CR to ASCII character of 13
tell application "System Events"
tell application "TextEdit" to activate
keystroke "n" using command down -- make new file
keystroke meow & CR & meow & CR & "woof!" & CR -- add some text
keystroke "s" using command down -- save
keystroke "story" & CR
keystroke "q" using command down -- quit
end tell

set the_file to (path to desktop) & "story.rtf" as text
set the_loc to (path to desktop) as text
set new_loc to (path to desktop) & "Test" as text
tell application "Finder"
if (exists (new_loc)) then
make new folder at alias the_loc with properties {name:"Test"}

duplicate the_file to new_loc with replacing
end if
duplicate the_file to new_loc with replacing
end tell

This script will create a file named "story" in TextEdit and save it to the desktop"

Next it will copy it to a folder named "test" and if the folder doesn't exist it creates it. and also places the file in the folder if that doesn't exist.

Is this the correct way to do this? Is there an onerr command I could use to better this script?

- SomeoneElse