I have been scripting for about 6 weeks now. And I finally hit two solid brick walls.
I ventured out to do my first folder action script, and for the life of me, I can’t figure out what I’m doing wrong. When I dropped files in the folder, nothing happens. The goal of the script is: When you drip files on to one folder, it moves it to another folder, and deletes the original. (I started simply with the duplicate. I will then worry about deleting the file.) If anyone has any idea what is wrong with the syntax, please let me know. I checked every book, every example, and the internet, and the syntax seems correct to me. Here is the script:
set destination_path to "ATG_HSQ:Applescript_Test:"
on adding folder items to this_folder after receiving these_items
repeat with current_file from 1 to count these_items
tell application "Finder"
duplicate file current_file to destination_path
end tell
end repeat
end adding folder items to
One thing I found really difficult about troubleshooting this script is you can’t break it up and see where the problem is happening as you can when you run a script in script editor. Any suggestions on how folks deal with troubleshooting Folder Action Scripts would be appreciated.
While trying to troubleshoot this script, I tried to duplicate the functionality in a script that I could run from Script Editor so I could at least test the basic functionality, and I ran into another problem that makes no sense. I spent hours on this simple thing, and I can’t figure it out. The script is:
set destination_path to "ATG_HSQ:Applescript_Test:"
set the_folder to (choose folder) as string
set these_items to list folder alias the_folder ¬
without invisibles
set result to these_items
repeat with i from 1 to count these_items
tell application "Finder"
duplicate file i to destination_path replacing yes
end tell
end repeat
The script is randomly copying files from my desktop to the destination_path. It is happening on more than one computer. (It always copies the same files. If the_folder has 5 files in it, then it copies 5 files from the desktop. If the_folder has 3, it copies 3)
I removed the repeat loop from the script and added the line:
set result to these_items
The script is returning the correct file names from these_items. Yet, as soon as I return the repeat loop it continues to copy files from the desktop.
I spent several hours yesterday, and explored every avenue I could think of to figure this out and hit a brick wall. Any help anyone can offer with these two issues would be greatly appreciated. Thanks in advance.