Hi I’m new to the forums but have done some Automator work in the past (nothing fancy) but I think I need some guidance with a project I want to acomplish.
I have recently installed a wireless security camera with sends motion detected images to my server via ftp. These images are dated in the file names as follows 2007-07-12_13-00-47.jpg and at the moment I have a folder full of them. What I want to create is an Automator script that will scan the folder at the end of each day and place the images in a sub folder which will then be dated for that day.
I have a feeling this IS possible but not sure where to start. Any help on this subject will be most appreciated.
Adrian
this asks for a folder (you can also specify a path) and sorts its files into subfolders.
The name of the subfolders are the first 10 characters of the file names (the date)
set theFolder to choose folder
-- set theFolder to "Mac HD:Users:path:to:folder:" as alias
tell application "Finder"
repeat with oneFile in (get files of theFolder)
set Nm to text 1 thru 10 of name of oneFile
move oneFile to my make_new_folder(theFolder, Nm)
end repeat
end tell
on make_new_folder(theFolder, fName)
try
return ((theFolder as Unicode text) & fName) as alias
on error
tell application "Finder" to return (make new folder at theFolder with properties {name:fName}) as alias
end try
end make_new_folder
Wow that was fast and it look like it should work but unfortunately I get the following error:
Finder got an error: Can’t get text 1 thru 10 of name of document file “2007-07-12_13-00-47.jpg” of folder “cam” of folder “Desktop” of folder “apt” of folder “Users” of startup disk.
Ok I’m no trying to take this script you sent me to the next level and turn it into a folder action and this is what I came up with:
on adding folder items to this_folder after receiving these_items
tell application “Finder”
repeat with these_items in (get files of this_folder)
set Nm to text 1 thru 10 of (get name of these_items)
move these_items to my make_new_folder(this_folder, Nm)
end repeat
end tell
end adding folder items to
on make_new_folder(this_folder, fName)
try
return ((this_folder as Unicode text) & fName) as alias
on error
tell application “Finder” to return (make new folder at this_folder with properties {name:fName}) as alias
end try
end make_new_folder
For some reason its not working can you cast your eye over it and tell me what I’m doing wrong
it doesn’t work, because these_items is a list containing the added items.
This code should work, but there is still missing a check whether the added item is a file or a folder
on adding folder items to this_folder after receiving these_items
tell application "Finder"
repeat with one_item in these_items
set Nm to text 1 thru 10 of (get name of one_item)
move one_item to my make_new_folder(this_folder, Nm)
end repeat
end tell
end adding folder items to
¢ But caution, you get a problem running this code.
If a new folder is created in the hot folder, the handler detects a new added item and starts the script again.
It would be a better idea, to use a destination folder outside the hot folder