?
Solved

Apple script file names

Posted on 2001-08-03
3
Medium Priority
?
252 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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

A common question or need, when setting-up a new Mac for someone would be to make all of the applications, installed, available from the dock. Many people often do not realize an application is installed unless it is in the dock. Creating a custo…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

764 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