Solved

Apple script file names

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bootcamp WinX 100% Disk 3 86
MAcbook and iPAd Pro 5 70
Mac Book Pro - Mac Mail - Yahoo Mail 5 63
Charging Macbook Pro 8 87
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 have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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