I’m working on an Apple Script which once a file is downloaded into a folder, it opens the file gets the contents then closes it and deletes it. On occassion after the file deletes a file of the same name appears in the folder. This file has no contents. Here is my script:
on adding folder items to this_folder after receiving added_items
delay 1
--if file "Macintosh HD:text:link.txt"
--opens link.txt and gets its contents
set theFile to (open for access file "Macintosh HD:text:writefile.asp" with write permission) as text
set fileContents to (read theFile)
try
close access theFile
end try
--Closes IE windows
tell application "Internet Explorer"
CloseWindow Title "Download Manager"
CloseWindow Title "thiswindow"
end tell
--grabs the file name from the text doc
set fileName to text 11 thru 18 of fileContents
--deletes link.txt and empties the trash
tell application "Finder"
delete file "Macintosh HD:text:writefile.asp"
end tell
the rest of the script takes the contents and does something with it
end adding folder items to
Any ideas on how I can fix this?