I have an applescript application that inputs a username and starts a download based on that username. In the app I use the code below to check if a file exists already and then rename the file if it does.
tell application "Finder" if exists "~/Downloads/Conversion/" & cbUsername & ".flv" as POSIX file then set x to 1 repeat set newCbFilename to cbUsername & "_" & x as string if exists "~/Downloads/Conversion/" & newCbFilename & ".flv" as POSIX file then set x to x + 1 else exit repeat end if end repeat copy newCbFilename to finalCbFilename display dialog "Filename already exists " & "File will be named: " & finalCbFilename & ".flv" buttons "OK" default button "OK" with title "Error" with icon caution else copy cbUsername to finalCbFilename end if end tell
All of a sudden yesterday it stopped working correctly. I had added the following code to ensure that the folder I was saving to existed.
tell application "System Events" if not (exists folder "~/Downloads/Conversion") then do shell script "mkdir ~/Downloads/Conversion" end if
Even when I comment out that code now it still doesn't work. What did I do wrong? end tell