Solved

Apple script file names

Posted on 2001-08-03
3
233 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
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
weed earned 200 total points
Comment Utility
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
Comment Utility
Thanks alot for the script.  seemed to work great.
0
 

Author Comment

by:aa799
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
iCloud Drive was introduced after iOS 8 was launched last year. This drive is Apple’s online storage device that lets users sync their files and access them from all their Apple devices.   There is a lot of data that is not automatically backed up…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now