[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Apple script file names

Posted on 2001-08-03
3
Medium Priority
?
254 Views
Last Modified: 2013-11-17
I have a zip disk with over 300 folders and files on it.   I want to append ".doc" to all the word documents on the disk so that i can easily open them on a PC.

I have been able to figure out how to append it to one selected file name but i can't loop through them.

tell application "Finder"
     set x to name of selection as text
     set name of selection to x & ".doc"    
end tell
 
--
aa799
0
Comment
Question by:aa799
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
weed earned 800 total points
ID: 6350593
Try this script........

tell application "Finder"
     activate
     
     set the_chosen_folder to (choose folder with prompt "Pick the folder containing the files to rename:")
     
     set the_prefix_or_suffix to ""
     repeat
          display dialog "Enter the prefix or suffix to use:" default answer the_prefix_or_suffix buttons {"Cancel", "Prefix", "Suffix"}
          copy the result as list to {the_prefix_or_suffix, the_choice}
          if the_prefix_or_suffix is not "" then exit repeat
     end repeat
     
     set the_list to (every file of the_chosen_folder) as list
     repeat with this_file in the_list
          if the_choice is "Prefix" then
               set the_new_file_name to the (the_prefix_or_suffix & name of this_file) as string
          else
               set the_new_file_name to the (name of this_file & the_prefix_or_suffix) as string
          end if
          my set_the_file_name_of(this_file, the_new_file_name)
     end repeat
     
end tell
beep 2

on set_the_file_name_of(this_file, this_file_name)
     tell application "Finder"
          activate
          set the_path_of_the_container_of_this_file to (the container of this_file) as text
          if not (exists file (the_path_of_the_container_of_this_file & this_file_name)) then
               try
                    set the name of this_file to this_file_name
               on error the_error_message number the_error_number
                    if the_error_number is -59 then
                         set the_error_message to "This name contains improper characters, such as a colon (:)."
                    else --the suggested name is too long
                         set the_error_message to "The name is more than 31 characters long."
                    end if
                    beep
                    set the_dialog_result to ?
                         (display dialog the_error_message default answer this_file_name buttons {"Cancel", "Skip", "OK"} default button 3)
                    if the button returned of the_dialog_result is "Skip" then return 0
                    set this_file_name to the text returned of the_dialog_result
                    my set_the_file_name_of(this_file, this_file_name)
               end try
          else --the name already exisits
               beep
               set the_dialog_result to ?
                    (display dialog "This name is already taken, please rename." default answer this_file_name buttons {"Cancel", "Skip", "OK"} default button 3)
               set this_file_name to text returned of the_dialog_result
               if the button returned of the_dialog_result is "Skip" then return 0
               my set_the_file_name_of(this_file, this_file_name)
          end if
     end tell
end set_the_file_name_of
0
 

Author Comment

by:aa799
ID: 6359425
Thanks alot for the script.  seemed to work great.
0
 

Author Comment

by:aa799
ID: 6359433
I would have liked it to go through all the folders in the fold I have choosen but, This is good enough.  Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Smartwatches: just a fashion accessory or a useful device for all? The Apple Watch (http://www.apple.com/watch/) was launched in April of 2015 and has become a new way for iPhone users to stay connected. Ranging from $349 to $17,000, the Apple Watch…
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question