Mac Help Forums


Reply
Thread Tools Display Modes

File sorting replacing problem

 
Member
LightGear's Avatar
Join Date: Nov 2005
Location: Florida
Posts: 72
 
      16th November 2005
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"
else if first_char is "p" then
move this_item to ":Volumes:Member Pics"
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
 
Reply With Quote
 
 
 
 
Ric Ric is offline
Senior Member
Ric's Avatar
Join Date: May 2004
Posts: 4,260
 
      16th November 2005
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
 
Reply With Quote
 
Ric Ric is offline
Senior Member
Ric's Avatar
Join Date: May 2004
Posts: 4,260
 
      16th November 2005
Amended script here...

--Open this script in a new Script Editor window.

regards

Ric
 
Reply With Quote
 
Ric Ric is offline
Senior Member
Ric's Avatar
Join Date: May 2004
Posts: 4,260
 
      16th November 2005
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
 
Reply With Quote
 
Member
LightGear's Avatar
Join Date: Nov 2005
Location: Florida
Posts: 72
 
      17th November 2005
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.

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
 
Reply With Quote
 
Ric Ric is offline
Senior Member
Ric's Avatar
Join Date: May 2004
Posts: 4,260
 
      17th November 2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iTunes Sorting John Varela Apps 10 23rd December 2011 05:13 AM
File sorting replacing problem. 00smita AppleScript 0 2nd August 2010 07:25 AM
sorting... -a- iPod 1 27th June 2008 04:05 AM
Replacing Power Supply--fan cable problem Captain Nemo Hardware 0 1st June 2008 07:35 PM
Replacing Palm Desktop User data file Peter Ceresole UK Macs 2 26th April 2005 06:46 AM


All times are GMT +1. The time now is 11:03 AM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
New book about Steve Jobs << take part in it!
Arjan (1 Hour Ago, 09:37 AM)

Help! Stupid computer is automatically logging me out
Elizaboo (12 Hours Ago, 10:41 PM)

URGENT Help. Crazy talk Mac!
Joeker (13 Hours Ago, 09:42 PM)

PDF Document
yura (22 Hours Ago, 12:13 PM)

Difficulties with internet speed (nothing to do with connection)
sammethh (1 Day Ago, 06:36 AM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51