Hi
I am new to applescript
I would like to create a script that scans a folder for new files every 30 seconds. When files drop into the folder I want the script to recognise them and perform a move.
The folder will have several different types of file and filename. The first 2 characters remain constant the rest of the filename is different on each file. Therefore I need to know how to add a wild card element to the script.
Hope someone can help - its driving me round the bend!
Hi,
You can create a stay open application that will check the folder every 30 seconds. Compile, and save the following code as a stay open application. Then run it and drop a file into your test folder. You will have to change the property to reflect the path to the folder at your location.
property watchFolder : "Mac HD:Desktop Folder:Test folder:"
on idle
tell application "Finder"
if the (count of files) in folder watchFolder > 0 then
--if the count of files in this folder is greater than zero then get the name of every file found
set fileList to get the name of every file of folder watchFolder as list
repeat with thisFile in fileList
--I'm am putting in an example of checking the first two characters
if (characters 1 thru 2 of thisFile) as string = "MN" then
--do your thing here
display dialog "Name starts with 'MN'" giving up after 5 --you can remove this (illustrative purposes only)
else if (characters 1 thru 2 of thisFile) as string = "WI" then --add as many of these as you need
--do something else here
display dialog "Name starts with 'WI'" giving up after 5 --you can remove this (illustrative purposes only)
else
--do something else if the first two characters don't fit into the other two categories
display dialog "Name did not start with 'MN' or 'WI'" giving up after 5 --you can remove this (illustrative purposes only)
end if
end repeat
else
return 30 --if nothing is found, check back in 30 seconds
end if
end tell
end idle
You could also use Folder Actions but that would require the folder be open in order to trigger the script on the items.
Best regards