Note: pasting the script in Script Editor you may get an error.
A "Not equal" sign (`) was changed while pasting here.
When in Script Editor you will get an error, part of the following line will be hilighted:
if myError ` "" then
It is close to the end of the program.
Well, to fix the problem, change the sign ` with a "Not equal" sign (you can get it pressing "Alt =").
Let me know if there's any problem! :-)
Best regards
Enzo Borri
Main Topics
Browse All Topics





by: eborriPosted on 2007-06-06 at 14:16:41ID: 19228644
It is possible.
---------- ---------- ---------- -
presentation.indd"
---------- ---------- ---------- -
Copy the following script; paste it into a ScriptEditor new script, customize it and save it as application enabling the option "Stay Open" checked.
Run the application and, any time you will insert the disk you indicated, the file/folder chosen will be copied replacing the previous versions.
IMPORTANT: I told "Replacing the previous version"! Be careful!!!
If the version in the destination drive is the most updated, quit this program before inserting the disk, OK????
Here is the script; customize it where you find these code lines (following the comments before these lines):
set SourceFile to "Macintosh HD:sample file"
set SourceFolder to "Macintosh HD:sample folder:"
set Destination to "Removable Disk:"
--------------------------
on run
global myError
global TriedToCopy
set myError to "" -- this variable will be empty in case there is no errors
set TriedToCopy to "" -- this variable will be empty in case the file was not copied. It is used to avoid to continuously copy the file on the destination drive.
end run
on idle
global myError
global TriedToCopy
(*Write in the next line the name of the file to be copied.
Example, the next line will look like:
set SourceFile to "Macintosh HD:Users:Enzo:Documents:My
*)
set SourceFile to "Macintosh HD:sample file"
(*Write in the next line the name of the folder to be copied.
Example, the next line will look like:
set SourceFolder to "Macintosh HD:Users:Enzo:Documents:"
NOTE: remember to put a colon (:) after the name of the folder!!!
*)
set SourceFolder to "Macintosh HD:sample folder:"
(*Write in the next line the name of the drive to copy onto.
Example, the next line will look like:
set Destination to "BackUp Drive:"
NOTE: remember to put a colon (:) after the name of the drive (or the folder in case you indicate a folder)!!!
*)
set Destination to "Removable Disk:"
(* MyTestFile must contain the name of the file used to test the presence of the drive to copy the file onto.
The file will be created in the same destination of the file and folder to be copied to.
The file's name must be written this way: Drive_Name:Test_File_name
Example: "TestFile" or, also, "TestFile.txt". The extension is not needed.*)
set MyTestFile to Destination & "DeleteMe"
tell application "Finder"
try -- I use the "Try" method to verify the drive presence. if fail, the drive is not present.
(*I try creating a file called "TestFile123.txt" If I can create it, the drive is present and there is no error.*)
open for access file MyTestFile without write permission
(*If I created the file, it is open and I cannot remove the drive uless I close the file, so& I close the file*)
close access file MyTestFile
set myError to ""
on error theError
set myError to theError
(*in case there was an error, and this mean the drive is not present, I use a variable to store the error.
I don't need to know wich error is; this is enough to know I cannot access this drive.*)
end try
if myError ` "" then
set TriedToCopy to ""
else
if TriedToCopy = "" then
set TriedToCopy to "Tried" -- So I don't copy the files more than once
tell application "Finder"
(*the following six (6) lines of code are used to copy a folder;
if unused, disable them placing two "minus sign" at the beginning of each line*)
try
move folder SourceFolder to Destination with replacing
on error CopyingError
beep
display dialog CopyingError with icon 0 with title "Cannot copy automatically!" giving up after 30
end try
(*the following six (6) lines of code are used to copy a single file;
if unused, disable them placing two "minus sign" at the beginning of each line*)
try
move file SourceFile to Destination with replacing
on error CopyingError
beep
display dialog CopyingError with icon 0 with title "Cannot copy automatically!" giving up after 30
end try
end tell
end if
end if
end tell
return 1 -- this way, it check for disk presence every 1 second; change this value for different timing.
end idle
--------------------------