I am trying to solve an issue with a renaming script, that needs to wait for a file to complete before the renaming process begins.
I am trying to do this by monitoring the files size. But i am having issues, as at the moment the script is just monitoring the file twice. Any help much appreciated!
from a struggling applescript newbie!
set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."
set theName to "test" -- the baseName
set n to 1 -- the starting number
set theExt to ".mov" -- name extension
repeat until n > 17
tell application "System Events"
repeat with i in (get files of watchFolder whose name ends with theExt)
set Size_1 to size of (files of watchFolder whose name ends with theExt)
delay 3
set Size_2 to size of (files of watchFolder whose name ends with theExt)
repeat until Size_2 = Size_1 -- repeat while sizes are different
delay 3 -- wait three seconds
end repeat
move i to destinationFolder
set name of the result to theName & n & theExt
set n to n + 1
end repeat
end tell
delay 1
end repeat
on quit
display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
if the button returned of the result is "Quit" then
tell application "System Events"
keystroke "." using command down
end tell
continue quit
end if -- If I don't continue the quit, the app will keep running.
end quit
Model: MacBook Pro
AppleScript: 2.3
Browser: Safari 534.58.2
Operating System: Mac OS X (10.6)
I have tried to make your script work better, but I haven’t tested it. I did drop the loop for only treating the first 17 files before quitting. I think I have made the script both more precise, and efficient, by only dealing with the currentFile, in the set of files that ends with ext. Furthermore, I removed the keypress command “.” as that isn’t necessary, a continue quit suffices!
All in all, I hope the script works, and please come back if there is any unforeseen side-effects! One sideffect may very well be that the file needs some time to be moved to the destination folder, but I am a little bit unsure of that, I know to much I guess. If the file are moved the unix way, then the entry of the directory is just removed, after a new link to the same file is created in the destination directory.
set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."
set theName to "test" -- the baseName
set n to 0 -- the starting number
set theExt to ".mov" -- name extension
tell application "System Events"
repeat with currentFile in (get files of watchFolder whose name ends with theExt)
set n to n + 1
set Size_1 to size of currentFile
delay 3
set Size_2 to size of currentFile
repeat until Size_2 = Size_1 -- repeat while sizes are different
delay 3 -- wait three seconds
end repeat
move currentFile to destinationFolder
set name of the result to theName & n & theExt
end repeat
end tell
on quit
display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
if the button returned of the result is "Quit" then
continue quit
end if -- If I don't continue the quit, the app will keep running.
end quit
repeat until Size_2 = Size_1 -- repeat while sizes are different
delay 3 -- wait three seconds
end repeat
cannot work, because Size 1 and 2 aren’t updated automatically.
You have to write something like this
.
set theExt to "mov" -- name extension
repeat until n > 17
tell application "System Events"
repeat with aFile in (get files of watchFolder whose name extension is theExt)
repeat
set Size_1 to size of aFile
delay 3
set Size_2 to size of aFile
if Size_2 = Size_1 then exit repeat
end repeat
move aFile to destinationFolder
set name of the result to theName & n & "." & theExt
set n to n + 1
end repeat
end tell
delay 1
end repeat
.
StefanK thankyou! your script didn’t work, but the proper if statement rules did, when i implemented them into my own script! thankyou so much! i Hope the good karma comes back two fold
in the end this is now the working script…
if anyone was interested, it is for a Sonic Arts project that needs to rename Skype calls as they are recorded on the fly, and then projected into a video mix patch done in Max/MSP. This applescript will now mean that the project is a success - and hence my PhD can continue
thankyou again to all!
set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."
set theName to "test" -- the baseName
set n to 1 -- the starting number
set theExt to ".mov" -- name extension
repeat until n > 17
tell application "System Events"
repeat with i in (get files of watchFolder whose name ends with theExt)
repeat
set Size_1 to size of (files of watchFolder whose name ends with theExt)
delay 3
set Size_2 to size of (files of watchFolder whose name ends with theExt)
if Size_2 = Size_1 then exit repeat -- repeat while sizes are different
end repeat
move i to destinationFolder
set name of the result to theName & n & theExt
set n to n + 1
end repeat
end tell
delay 1
end repeat
on quit
display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
if the button returned of the result is "Quit" then
tell application "System Events"
keystroke "." using command down
end tell
continue quit
end if -- If I don't continue the quit, the app will keep running.
end quit