File sorting replacing problem

Joined
Nov 16, 2005
Messages
72
Reaction score
0
I am have made a folder action. It works in for the most part but where I am having a problem is it will not replace the file once it aready exists.

What I am tring to do is but files in alphabetitcal order based on the first letter of the file. and but it in the subfolder.

also if anyone can stream line this any better I am all ears. I have tried different replace commands I could come up with but it did not work.

Any help anyone could give I would be thankful

This is the Code that work with out the replacing function

tell application "System Events"
set these_files to every file of folder "Volumes:Member Pics"
repeat with i from 1 to number of items in the these_files
set this_item to item i of the these_files
set this_info to info for this_item
if visible of this_info is true then
set file_name to name of the this_item
set the first_char to (character 1 of the file_name) as string
beep 1
display dialog first_char buttons {"OK"} default button 1
if first_char is "a" then
move this_item to ":Volumes:Member Pics:a"
else if first_char is "b" then
move this_item to ":Volumes:Member Pics:b"
else if first_char is "c" then
move this_item to ":Volumes:Member Pics:c"
else if first_char is "d" then
move this_item to ":Volumes:Member Pics:d"
else if first_char is "e" then
move this_item to ":Volumes:Member Pics:e"
else if first_char is "f" then
move this_item to ":Volumes:Member Pics:f"
else if first_char is "g" then
move this_item to ":Volumes:Member Pics:g"
else if first_char is "h" then
move this_item to ":Volumes:Member Pics:h"
else if first_char is "i" then
move this_item to ":Volumes:Member Pics:i"
else if first_char is "j" then
move this_item to ":Volumes:Member Pics:j"
else if first_char is "k" then
move this_item to ":Volumes:Member Pics:k"
else if first_char is "l" then
move this_item to ":Volumes:Member Pics:l"
else if first_char is "m" then
move this_item to ":Volumes:Member Pics:m"
else if first_char is "n" then
move this_item to ":Volumes:Member Pics:n"
else if first_char is "o" then
move this_item to ":Volumes:Member Pics:eek:"
else if first_char is "p" then
move this_item to ":Volumes:Member Pics:p"
else if first_char is "q" then
move this_item to ":Volumes:Member Pics:q"
else if first_char is "r" then
move this_item to ":Volumes:Member Pics:r"
else if first_char is "s" then
move this_item to ":Volumes:Member Pics:s"
else if first_char is "t" then
move this_item to ":Volumes:Member Pics:t"
else if first_char is "u" then
move this_item to ":Volumes:Member Pics:u"
else if first_char is "v" then
move this_item to ":Volumes:Member Pics:v"
else if first_char is "w" then
move this_item to ":Volumes:Member Pics:w"
else if first_char is "x" then
move this_item to ":Volumes:Member Pics:x"
else if first_char is "y" then
move this_item to ":Volumes:Member Pics:y"
else if first_char is "z" then
move this_item to ":Volumes:Member Pics:z"
end if
end if
end repeat
end tell
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Hi LightGear and welcome...

try this...

change tell application "System Events"
to tell application "Finder"

then on each line that says...

move this_item to ":Volumes:Member Pics:z"

change it to...

move this_item to ":Volumes:Member Pics:z" replacing yes

give that a go !

regards

Ric
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
It can be quite tricky to 'know' when to use "System Events" instead of "Finder"...

...the best advice I can give is to look in the Dictionaries of each, ( Script Editor-->Open Dictionary-->Select the App) if you look in "System Events' dictionary there is no 'replacing' whereas in the 'Finder' dictionary there is...

If in doubt have a look...

tell application "System Events"
sleep
end tell

tell application "Finder"
sleep
end tell

both do the same thing !

regards

Ric
 
Joined
Nov 16, 2005
Messages
72
Reaction score
0
Thanks RIC I will give it a shot. Also is there a better way to write this code.
Say like this...
I get the first letter of this_item and move it to a folder with the same letter. :D

I am not sure if this is possible but if it is, I would be able to make the code a lot shorter

Thanks again for the help :)
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
No problem...

I'll have a think about how you could make the code smaller/neater...but sometimes if it does what you want then it's best to leave as is, as long as it works !

The idea is that the AppleScript should save you time ;-) Not create more problems for you...

...I know what you mean though !

regards

Ric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top