Tuesday, August 20, 2019

#1 2005-07-13 12:59:29 pm

cthompson
Member
Registered: 2005-06-23
Posts: 7

File returns after delete

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:

Applescript:

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?


Filed under: internet, Finder

Offline

 

#2 2019-08-10 03:00:23 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 425

Re: File returns after delete

cthompson wrote:


    --opens link.txt and gets its contents
    set theFile to (open for access file "Macintosh HD:text:writefile.asp" with write permission) as text



HERE. This code line creates second object (add new file to HOT folder), and triggers from this code line folder action before you complete the previous processing. From here you lose control on your HOT folder.

Applescript:


on adding folder items to this_folder after receiving added_items
   delay 1
   set fileContents to (read file "Macintosh HD:text:writefile.asp")
   
   --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" to delete file "Macintosh HD:text:writefile.asp"

the rest of the script takes the contents and does something with it

end adding folder items to

Last edited by KniazidisR (2019-08-10 03:32:14 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)