Hi, my AppleScript below exhibits an unwanted behavior when the “Duplicate” function is being executed.
This script automatically copies movie files from a USB drive to my computer when inserted. If there are only 1 - 3 movies it works fine, however, if there are several movies and copying lasts more than 2 minutes the script continues on to the next steps in the script.
For example: There are 9 movies to be copied, 4 to the “Movies” folder and 5 to the “Kids Movies” folder > I plug in the USB and the script starts copying the first 4 movies - the standard file copy dialog box appears > After 2 minutes another copy dialog box appears showing the other 5 movies copying into the Kids Movies folder > after 2 more minutes my “USB Auto Eject” dialog box appears, 60 secs later it disappears as it should (the movies are still being copied)> then my USB Ejected dialog box appears and disappears after 110 secs. At this point the USB drive is supposed to be ejected, it does not eject, the movies are still being copied. When the copying completes the file copy dialog box disappears. All the movies were copied correctly and the USB drive was not ejected. And, of course, I do not want the USB drive to eject until copying is complete.
So, my question is how to modify this script so that it pauses when copying, only as long as necessary, until the file copy process completes on each “Duplicate” function?
Thanks in advance for any help with this.
property Volumes : {"Entertainment Center", "Entertainment Center Files", "OS X Base System", "USB 750"} -- add as needed
property videoExtensions : {"avi", "mov", "mpg", "mp4", "wmv", "mkv"}
set movieVolume to alias (POSIX file "/Volumes/Entertainment Center Files/Entertainment/Movies")
set kidsmovieVolume to alias (POSIX file "/Volumes/Entertainment Center Files/Entertainment/Kids Movies")
tell application "System Events"
set rootVolumes to disk item (POSIX file "/Volumes" as text)
set allVolumes to name of every disk item of rootVolumes
set numofallVolumes to count of allVolumes
try
set thisVolume to item 3 of allVolumes
on error errorMessage number errorNumber
set _error to errorMessage
set _errorNum to errorNumber
if errorNumber is -1728 then
display dialog "There are no USB Drives Mounted." buttons {"OK"} default button 1 with title "Did You Insert a USB Drive? . . . ." giving up after 10
if button returned of result is "OK" or gave up of result then error number -128
end if
end try
tell application "Finder"
activate
delay 2
if thisVolume is in the Volumes then
set runScript to 1
else
try
if exists alias (POSIX file ("/Volumes/" & thisVolume & "/movies") as text) then set runScript to 2
on error errorMessage number errorNumber
set _error to errorMessage
set _errorNum to errorNumber
if errorNumber is -1700 then
display dialog "No Movies Folder on This USB Drive --- There Must be a *Movies Folder* or a *Kids Movies Folder* for Copy Function to Activate . . . . . USB Drive Will Eject in 60 Secs" buttons {"OK", "No"} default button 1 with title "Movie Copy Error !!" giving up after 60
if button returned of result is "No" then
error number -128
else
if button returned of result is "OK" or gave up of result then
eject thisVolume
display dialog "U S B D r i v e E j e c t e d - O K t o R e m o v e" buttons {"Not Necessary to Click this Button"} default button 1 giving up after 10
return
end if
end if
end if
end try
end if
if runScript = 1 then error number -128
if runScript = 2 then
try
duplicate (items whose name extension is in the videoExtensions) in alias (POSIX file ("/Volumes/" & thisVolume & "/movies") as text) to movieVolume
on error errorMessage number errorNumber
set _error to errorMessage
set _errorNum to errorNumber
if errorNumber is -15267 then
display dialog "This Movie Already Exists in the Movies Folder" buttons {"OK", "No"} default button 1 with title "Movie Copy Error !!" giving up after 10
if button returned of result is "No" then
error number -128
else
if button returned of result is "OK" or gave up of result then
eject thisVolume
display dialog "U S B D r i v e E j e c t e d - O K t o R e m o v e" buttons {"Not Necessary to Click this Button"} default button 1 giving up after 10
return
end if
end if
end if
end try
try
duplicate (items whose name extension is in the videoExtensions) in alias (POSIX file ("/Volumes/" & thisVolume & "/kids movies") as text) to kidsmovieVolume
on error errorMessage number errorNumber
set _error to errorMessage
set _errorNum to errorNumber
if errorNumber is -15267 then
display dialog "This Kids Movie Already Exists in the Kids Movies Folder" buttons {"OK", "No"} default button 1 with title "Movie Copy Error !!" giving up after 10
if button returned of result is "No" then
error number -128
else
if button returned of result is "OK" or gave up of result then
eject thisVolume
display dialog "U S B D r i v e E j e c t e d - O K t o R e m o v e" buttons {"Not Necessary to Click this Button"} default button 1 giving up after 10
return
end if
end if
end if
end try
display dialog "USB Drive will Auto Eject in 60 Seconds or Click OK. . . . . . ." buttons {"OK", "No"} default button 1 with title "Copy Function Completed - Eject?" giving up after 60
if button returned of result is "No" then
error number -128
else
if button returned of result is "OK" or gave up of result then eject thisVolume
display dialog "U S B D r i v e E j e c t e d - O K t o R e m o v e" buttons {"Not Necessary to Click this Button"} default button 1 giving up after 110
end if
end if
end tell
end tell
Model: MacMini
Browser: Safari 603.2.4
Operating System: macOS 10.12