Solved

Apple script file names

Posted on 2001-08-03
3
241 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 200 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

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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