Applescript giving error 1728 when checking if file exists I'm trying to make compressing a video file using HandBrake easier through applescript and have been basing most of the code off of templates I've found.
At this point in the code, the user has specified the source file and the destination folder.
Instead of HandBrakeCLI just blindly overwriting a file with the same name in the destination folder, I wanted Finder to do a check and, if a file with the same does already exist in the destination folder, then I wanted to have the filename appended with the current date and time before the extension.
Everything worked fine until I started adding the "if exists" code.

Here's the chunk of code:

tell application "Finder"
    set newFilepathPOSIX to POSIX path of dest_folder
    set newFilepathPOSIX to newFilepathPOSIX &amp; "video.mp4"
    -- Check if file with same name exists
    if exists file newFilepathPOSIX then
        display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
        if result = {button returned:"No"} then
            set newFilepathPOSIX to POSIX path of dest_folder
            set newFilepathPOSIX to newFilepathPOSIX &amp; "video" &amp; getDateAsString &amp; ".mp4"
        end if
    end if
    set newFilepathPOSIX to quoted form of newFilepathPOSIX
    set shellCommand to "/Volumes/Flash Drive/HandBrakeCLI -i " &amp; origFilepathPOSIX &amp; " -o " &amp; newFilepathPOSIX &amp; " --preset=\"Classic\""
end tell

to getDateAsString from t
    set creationDateString to year of t as string
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; getMonthNum(t) as string)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; day of t as string)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; hours of t as string)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; minutes of t as string)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; seconds of t as string)
    return creationDateString
end getDateAsString


Here's what it returns:

exists file "/Users/me/Box Documents/My Folder/video.mp4"
    --&gt; false


If I add "as POSIX file" to the "if exists" line, this is what it returns:

get file "/Users/me/Box Documents/My Folder/video.mp4"
    --&gt; error number -1728 from file "/Users/me/Box Documents/My Folder/video.mp4"
exists file "My HD:Users:me:Box Documents:My Folder:video.mp4"
    --&gt; true
display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    --&gt; {button returned:"No"}


After this, it errored out.
Totally new at this so hopefully I've given enough detail without giving away way too much detail.
Try:

set dest_folder to POSIX path of dest_folder
set newFilepathPOSIX to dest_folder &amp; "video.mp4"

tell application "System Events" to exists file newFilepathPOSIX
if the result then
    display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    if button returned of the result = "No" then
        beep
        --Insert your code here
    end if
end if


EDIT

 set handPath to "/Volumes/Flash Drive/HandBrakeCLI"
set dest_folder to POSIX path of dest_folder
if text -1 of dest_folder ≠ "/" then set dest_folder to dest_folder &amp; "/"
set newFilepathPOSIX to dest_folder &amp; "video.mp4"

tell application "System Events" to exists newFilepathPOSIX
if the result then
    display dialog "There is already a file named \"video.mp4\". Do you want to replace the file?" buttons {"Quit", "No", "Yes"} cancel button 1
    if button returned of the result = "No" then set newFilepathPOSIX to dest_folder &amp; "video" &amp; getDateAsString(current date) &amp; ".mp4"
end if

set shellCommand to quoted form of handPath &amp; " -i " &amp; quoted form of origFilepathPOSIX &amp; " -o " &amp; quoted form of newFilepathPOSIX &amp; " --preset=\"Classic\""
do shell script shellCommand

on getDateAsString(myDate)
    set creationDateString to year of myDate as string
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; (month of myDate as integer) as text)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; day of myDate as text)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; hours of myDate as text)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; minutes of myDate as text)
    set creationDateString to creationDateString &amp; text -2 thru -1 of ("0" &amp; seconds of myDate as text)
end getDateAsString