I am completely confused here. For some reason my code below would only work when the file needed to be downloaded doesn't exist initially. However when I try running it again (the file being already there) and download the file to a tempfile and replace the old file. It wouldn't replace. Below is my code.
The download is successful but attempting to perform a delete and then rename won't work for some reason.
You can test out my code:
my phoneHome()
on phoneHome()
set iserror to updatePricing("PriceList")
if iserror then
display dialog "Unable to contact server to determine if updated pricing is needed. Will proceed using the most recently downloaded pricing."
else
display dialog "Download complete. Your local price list has been updated."
end if
end phoneHome
on updatePricing(theMarket)
set pricefile to "index.html"
set getFile to "http://www.apple.com/" & pricefile
set tempPath to ("Mac OS Drive:Users:macaroni:Bin:tempfile.txt")
set pricePath to ("Mac OS Drive:Users:macaroni:Bin:pricefile")
try
tell application "URL Access Scripting"
download getFile to file tempPath replacing yes
tell application "Finder"
if file pricePath exists then delete file pricePath
set name of file tempPath to pricefile
end tell
end tell
return false
on error
return true
end try
end updatePricing