Using Automator to Rename Files

I can't figure out how to rename files so that the number in the name is in parentheses. For example Dog 1.jpg should be changed to Dog (1).jpg. How can I accomplish this in Automator?

ok. the following should work. paste it into AppleScript Editor. select the files you want to rename in finder and press "run" in script editor. you might want to test it on a small number of files first.
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
tell application "Finder"
set selected_items to selection
repeat with this_item in selected_items
set current_name to name of this_item as text
set current_extension to name extension of this_item
set length_extension to length of current_extension
set name_no_ext to text 1 thru (-length_extension - 2) of current_name
set AppleScript's text item delimiters to " "
if (number of text items of name_no_ext > 1) then
set z to last text item of name_no_ext --get the number at the end of the name before the extension
set name of this_item to do shell script "echo " & quoted form of current_name & "|sed 's/" & z & "." & current_extension & "/(" & z & ")." & current_extension & "/'"
end if
set AppleScript's text item delimiters to ""
end repeat
end tell</pre>

Similar Messages

  • How can i use automator to rename files erasing first 3 digits of their name?

    Actually in the files i am trying to rename the first 2 digits are numbers then space and then there is the file name i want to use. Hope this helps.

    Open the AppleScript Editor in the /Applications/Utilities/ folder and paste in the following text:
    tell application "Finder"
    set the_items to items of window 1
    repeat with this_item in the_items
    set name of this_item to (items 4 thru -1 of (get name of this_item)) as string
    end repeat
    end tell
    Navigate to the folder containing those files in the Finder and run the script.
    (65537)

  • I used automator to rename some pages files, and now they can't be opened

    I used automator to remove some text from the filenames of a group of pages files, and now they can't be opened. What went wrong?

    Did you by any chance remove the file type extension?
    Walt

  • Using automator to delete files with out moving them to the trash

    My boss and I work for a school district and we have been fight the ever losing battle of keeping kids from using usb drives and ipods on the computers. We have it fixed on the server accounts so they can't. But the local accounts they can do as they please. So we have found the files that we need to remove Example ( IOUSBMassStorageClass.kext, IPodDriver.kext, ITunesPhoneDriver.kext ) I have tried to use automator to delete these files by creating an application. Well it can't remove them because its need sudo access. So no im trying to figure out how to create a apple script to do so. I know once the files are removed the machines needs to restarted. So im not sure how to include a restart command too.
    Any help on how to get this working would greatly appreciated. We have over a 600 machines to do this to. I know that there maybe mixed feeling about removing these functions but we have to fallow our board digital computer policy Primarily ever since the RIAA has been cracking down.

    Hi Northridge, and a warm welcome to the forums!
    I'd use the Terminal...
    In Terminal type man mv & man reboot
    You can execute those commands preceded by sudo, like...
    sudo mv /Library/Extensions/IOUSBMassStorageClass.kext /Library/Extensions/IOUSBMassStorageClass.kext.old
    This one just renames it, but you could move it wherever you want.

  • Using Automator to "cat" files

    Hi all-
    I was wondering if someone could help me with an Automator workflow. I've never used Automator... but I'm pretty sure it can do what I'm looking for.
    I need it to "cat" .MTS (AVCHD) files for me. I'd like it to order them alphabetically, then cat and output to a single file.
    Is this possible?
    Thanks!

    Yea, I figured out that much. My end goal is to take two .MTS (video) files and drop them onto an automator app and have it cat the files. I just don't know how to get there.
    I'm not good with scripting, and I've never written an Applescirpt, but I know I'm missing something here. Just having the "cat" command in the "Run Shell Script" action isn't working. I'm thinking I have to specify somehow for it to "use the two files I just gave you and run the cat command on them, then output".
    Does that make sense?
    Here is what I have so far in Automator:
    1. App recieves files or folders as input
    2. Sort Finder Items   
         -by Name in Ascending order
    3. Run Shell Script
         -cat
    4. Move Finder Items
         -to Desktop.
    Thanks!

  • Use Automator to move files and folder structure to another folder, retaining destination contents

    I have been struggling trying to setup Automator to move files and folder structure to another folder, retaining the destination contents.  Basically, I need to add files at the destination, within the same folder structure that exists at the source.  Here's some details about the scenario:
    -I have PDF files that I create on a seperate computer than I my daily use machine
    -For security reasons, the source computer doesn't have access to any shares on the destination computer
    -The destination computer has access to shares on the source computer
    -I want to delete the original PDFs at the source after they are moved or copied
    I haven't been able to get Automator to move or copy the folder contents (files and subfolders) without dropping everything copied at the top level of the destination, resulting in many duplicate folders and a broken folder structure.
    So far I've only had luck getting this to work at the command line, but I'd really like to have this setup in Automator so that I could have either a service or application that I could use for any folder, prompting for the source and destination folders.  I'm a relatively new Mac user with limited Linux experience, so this is the command that I've cobbled together and currently accomplishes what I'm looking for:
    ditto /Volumes/SMB_Temp/SOURCE ~/Desktop/Documents/DESTINATION
    cd /Volumes/SMB_Temp/SOURCE
    find . -type f -name "*.pdf" -exec rm -f {} \;
    Thanks for any ideas!

    If you have a command-line syntax that works, why not just create an Automator workflow with a single 'Utilities -> Run Shell Script' action, where that action has your (working) shell commands?
    Seems way, way simpler to me than trying to reinvent the wheel and transcribe shell commands into individual Automator actions

  • How to use automator to duplicate files into separate folder?

    i am running the latest version of Yosemite just to clarify.
    My question is, is it possible to use automator to automatically copy a file thats added to a folder to a separate folder?
    to clarify, i have a drive account that has all my university work stored in a folder called university, i also have a folder on my HD called university.
    When i work on something i open it from the university folder on my HD, and when im done working i have to copy the file manually into the drive folder.
    Is there any way that i can use automator to detect when a file gets saved in a folder on my hard drive and automatically copy it to my drive folder?

    Hello,
    I really don't have much of an idea, but since no one has replied yet, I'll offer this...
    I wonder if it's a matter of having to clear browser caches & reloading the page?

  • Using Automator for photography file needs

    I've been looking on here but can't find a way to do what I need done exactly.
    I shoot in both raw and jpeg and I want to be able to run one action on a folder to do the following.
    Arrange the files in a folder by name and in ascending order.
    Create 2 folders in the input folder. 1 called RAW and copy all the raw files (.nef) to that folder and the other called JPEG and copy all the jpeg files to that folder.
    Rename the files fro _dsc4356.jpg to macshoot0001.jpg and in the raw folder rename all the files as well.
    Is this possible using the automator?
    Thanks.

    Hi,
    In Automator :
    add action "*Run Shell Script*"
    Select "/bin/bash" in Shell popup menu
    Select "*as arguments*" in pass input: popup menu
    Paste this text in the action.
    baseName="macshoot"
    padding=0000 ## 3 zero pad
    for f in "$@"; do
    if [ -d "$f" ]; then ## is a directory
    i=0
    cd "$f"; /bin/mkdir -p "$f"/{RAW,JPEG}
    for aJPG in "$f/"*.jpg ; do
    if [ -f "$aJPG" ]; then
    ((i++)); index=${padding:${#i}}$i;
    /bin/mv "$aJPG" "JPEG/$baseName$index.jpg"
    fi
    done
    i=0
    for aNEF in "$f/"*.nef ; do
    if [ -f "$aNEF" ]; then
    ((i++)); index=${padding:${#i}}$i;
    /bin/mv "$aNEF" "RAW/$baseName$index.nef"
    fi
    done
    fi
    done
    That's all.
    This shell proceed folder(s) only, if the input is file(s), it do nothing
    Message was edited by: Jacques Rioux

  • Use Automator to move files to trash

    I've spent quite a bit of time trying to work out how to move files with automator to another folder - finally worked this out using a folder action.
    I am now trying to do similar, but this time using a folder action to move files to the trash.  Again, I don't seem to be getting this right.  I have the following:
    There are definitely files in the folder that meet the criteria - but the workflow is not working.  Any suggestions, please?
    Cheers,
    Mike

    sdiaz34 wrote:
    The external hard drive was partitioned to have a back up drive for time machine and another drive for other (pics&vids) use.
    If it is possible can the automator task then trash all files in original pictures subfolder when task is complete to avoid any memory use on macbook air?
    You really don't want to do that. 
    You'll have only one copy of the files, on the external HD.  When (not if) it fails, they'll be lost.  
    For best results, get another external HD for your photos.  Then let Time Machine back up both your internal HD and the external.  See Time Machine - Frequently Asked Question #32 for details.

  • I was wondering if it was possible to use Automator to move files based on the filename.

    Hi,
    I'm kind of new to Automator and I'm trying to come up with a sequence that will severely save me a few hours a day moving files from two larger folders into smaller folders. Basically the setup is that I have two folders, one constantly being populated with images and the other with video files. They each have file names starting with a two digit number (i.e. 12, 11, 10...) or "BG" and then a two digit number (i.e. BG12, BG11, BG10...) with the digits corresponding to a year. Essentially, I'd need to move the files into folders corresponding to the year (i.e. files starting with BG12 and 12 would be moved to 2012, files starting with BG11 and 11 would be moved to 2011, etc). As it stands now, I've only been able to get the 2012 folder populated. Any help would be greatly appreciated. Thanks.

    Hi,
    Here's a solution that uses a script, because it is not possible, at least to make twenty or more Workflows
    In Automator :
    Create a new worflow.
    Add the action "Run Shell Script", select "/bin/bash" in the popup menu
    Cut the text in the action.
    Copy/paste this script in the action :
    targetsDir=('/Users/jack/Desktop/MyImagesFolder' '/Users/jack/Desktop/MyVideosFolder')
    destDir=('/Users/jack/Desktop/yearImageFolder' '/Users/jack/Desktop/yearVideoFolder')
    for i in 0 1;do
          subfolder="${destDir[$i]}"/20
          for each in "${targetsDir[$i]}"/*;do
                if [ ! -d "$each" ];then ## not a directory
                      name=${each##*/};
                      if [[ $name =~ ^([0-9]{2})|^..([0-9]{2}) ]]; then
                            [[ $name =~ ([0-9]{2}) ]] && year=${BASH_REMATCH[1]};
                            /bin/mv -n "$each" "$subfolder$year"
                      fi
                fi
          done
    done
    Replace the paths in the first line by the path of your Images Folder  and Video Folder, use drag/drop between the simple quote ''
    Replace the paths in the second line by the path of your destibation Folders, use drag/drop between the simple quote ''.
    This script will not overwrite existing files, If you want to replace the existing file, use the /bin/mv -f instead of /bin/mv -n
    That's it.

  • Using Automator to copy files from a Windows network

    This has been covered before, but the solution didn't work for me, so excuse the mainly copy-and-paste article:
    I wrote an automator workflow to copy a chosen file located on a PC on the local network.
    Here is the workflow:
    Get Specified Servers
    Mount Servers
    Ask for Finder Items
    Copy Finder Items
    The workflow executes fine up until the workflow actually finishes copying all the files. The automator complains that the Copy Finder Items errors with the following message:
    Can't read directory contents: /Volumes/Files
    The other thread suggests choosing "Ignore Input" for the "Ask for Finder Items" action, which I did. But now I have a different error:
    Couldn't create: /Users/{my name}/Desktop/filename.xlsx
    Any ideas? Thanks!

    This has been covered before, but the solution didn't work for me, so excuse the mainly copy-and-paste article:
    I wrote an automator workflow to copy a chosen file located on a PC on the local network.
    Here is the workflow:
    Get Specified Servers
    Mount Servers
    Ask for Finder Items
    Copy Finder Items
    The workflow executes fine up until the workflow actually finishes copying all the files. The automator complains that the Copy Finder Items errors with the following message:
    Can't read directory contents: /Volumes/Files
    The other thread suggests choosing "Ignore Input" for the "Ask for Finder Items" action, which I did. But now I have a different error:
    Couldn't create: /Users/{my name}/Desktop/filename.xlsx
    Any ideas? Thanks!

  • Using AppleScript to rename file as current date

    Hi, I created a script to record a radio show on a daily basis.
    I would like apple script to set the name of the files as the day´s date.
    any help would be appreciated,
    Thank you very much

    Once you've got a file name and path in the Finder, you can use this:
    tell application "Finder"
    set name of file "path:to:file" to (month of (current date)) & " " & day of (current date) & ", " & year of (current date) as string
    end tell
    (14444)

  • Renaming files in folder

    trying to figure out how to use automator to rename files within a folder.
    searched on youtube but none of the methods seem to work on my mac.
    if anyone knows of a great tutorial for this i would love to have it.
    thanks'
    Owen

    Sorry, I'm not sure what you mean. Are you referring to the Downloads folder that Mac OS X sets up by default in your user's home directory? If so, you rename files in that folder the same as you would any other folder. The Downloads folder does not (unless something's amiss with the permissions on your system) restrict anything and isn't any sort of "special" folder in terms of how it behaves.
    If that's not what you meant, please post back and explain further.
    Regards.

  • How to use Automator to batch convert xls/xlsx files into tab OR pipe delimited text file.

    If you have answer, please provide specific and detailed steps.
    Situation 1:
    Start:
    150+ files in .xls OR .xlsx format
    data contains many characters EXCEPT "Tab"
    Process:
    Use Automator to:
    Select Files from Finder window
    Convert selected files from xls/xlsx to TAB-DELIMITED file format
    End:
    150+ files in .txt format
    files have identical names to those from "Start:"
    data is TAB-DELIMITED
    Situation 2:
    Start:
    150+ files in .xls OR .xlsx format
    data contains many characters EXCEPT | (pipe, vertical bar)
    Process:
    Use Automator to:
    Select Files from Finder window
    Convert selected files from xls/xlsx to |-delimited file format
    End:
    150+ files in .txt format
    files have identical names to those from "Start:"
    data is "|"-delimited

    If your post is addressed to my response then the answer is you have to write your own or search on-line to see if something exists to do what you want.
    As you note there is no pre-built script for this.
    regards
    Message was edited by: Frank Caggiano - Are you certain there isn;t something in Excel to export as a tab delimited file?
    This link Convert An Excel Spreadsheet To A Tab Delimited Text File seems to indicate that the function is in Excel already.

  • Automator: Impossible to rename file using automator under Mac OS X Lion

    Hi,
    Before upgrade my iMac to MAC OS X Lion 10.7.2, I had service created with automator under snow leopard in order to rename my pictures file names by blocks instead of one by one. Since I'm using Lion, this one doesn't work anymore. I have completely recreate the service under Lion and the results is the same.
    You can find below my workflow that is easy. The problem is the message error in the history of automator application. The message is "impossible to rename file "file name" because this one should create conflict with existing file". I already test a lot of times with different name where I'm sure that this one doesn't exist on my Mac but all the time without success (verify also with search function under mac)
    If somebody can help me, it would be very interesting because I already tried to find answer on internet without success too.
    Thanks in advance for your help.

    the whole automator and in particular the record action was substantially rewritten in snow leopard. and the record action is slow, unreliable and you can't trouble-shoot it. it's a wonder it works at all. the only advice i can give is to use it as little as possible. if at all possible avoid it altogether. if you do need to use it try using keyboard strokes instead of the mouse movement. for example. use command+c and command+v for copying and pasting and use tabbing to choose the correct box on the page.

Maybe you are looking for