Script for Automator to reorder text in file/folder name.

I have a folder full of pictures named by their first and last names. I need them to be renamed by listing them by last name first, first name last in order to get them alphabatized properly. Anybody out there have a nice Automator script for me to make this happen? I'm new.
Looking for it to look like this:
Brown, John

Try this (should work for "John H Smith" --> "Smith John H" as well):
The Run Shell Script Action is:
for f in "$@"
do
    basename=${f##*/}
    path=${f%/*}
    ext=${f##*.}
    name=${basename%.*}
    if [[ "$name" =~ \  ]]; then
        fname=${name% *}
        lname=${name##* }
        name="$lname $fname"
        mv "$f" "$path/$name.$ext"
    fi
done
If you want a comma, then change: name="$lname $fname" to name="$lname, $fname"
As with all scripts, back-up the files before running

Similar Messages

  • Script or Automator to reorder text in file/folder name

    Hello,
    Similar to this discussion: https://discussions.apple.com/thread/2632228, I would like to reorder a large number of folder names. Currently, they are set up as follows:
    "Name - Year" and would like to change them all to "Year - Name". I have over 200 folders named in this format so I need to find either a way to do this via the automator or via a script. So far I can't find what I need in the Automator. Any ideas? Thank you

    try this:
    set folderList to choose folder with multiple selections allowed
    tell application "System Events"
              repeat with thisFolder in folderList
                        set folderName to name of thisFolder
      -- assumes none of the folders have extensions, or anything aside from "Name - Year", and that there are no spaces inside the name or year
      -- it can be generalized to deal with that, if needed
                        set {oldTID, my text item delimiters} to {my text item delimiters, {" ", "-"}}
                        tell folderName
                                  set {n, d} to {first text item, last text item}
                        end tell
                        set my text item delimiters to oldTID
                        set name of thisFolder to d & " - " & n
              end repeat
    end tell

  • A Few SEO Questions: Alt="" text and file/folder names.

    I've been reading about the Dark Art of SEO and frankly, a lot of it is more confusing than I anticipated.  Anyway, I'll summarise a bit here.I have read that:
    File/folder names are better with meaningful words and hyphenated words.  so DCM000123.jpg in a folder called galimg would be better as: /gallery-images/painting-title-here.jpg
    Alt="" text can add to the content of your pages.
    My thinking underneath this relates to a gallery site I built with around 200 individual paintings in it.  So the site has a lot of content but not a lot of text.  I wonder if I should start trawling through all of this to change the file names and folders and add alt="" text more meaningfully to help with SEO?
    So if my thinking is OK, here are the questions.
    How would you put the alt="" text on individual images?  I imagine that it should just be a straight-forward, what-you-see description?  But there are a few other options.  Suppose I have an image that the artist has titled, "Cattle on a Hill" and it's an oil on canvas.  I could make that into,
    alt="Oil on Canvas: Cattle on a Hill" or
    alt="Cattle on a Hill" or
    alt="A group of cows grazing in pasture under moonlight." or
    Suppose I have 20 images in a portrait gallery:
    alt="Portrait.  Oil on canvas: Joe Bloggs" or
    alt="Portrait.  Joe Bloggs" or
    alt="Man with grey hair wearing a blue shirt sitting on a bench" or
    alt="Portrait painting.  Oil on canvas. Joe Bloggs: Man with gray hair wearing a blue shirt sitting on a bench"
    The second part of the question also includes the problem that if I have 20 images in a single gallery page and I put "Portrait painting" in each alt="" text is that going to look like key word stuffing?
    Now on to the file name thing.  Should the file names be portrait-painting-01 and so on or should they be Cattle-on-hill or what?
    Final question: am I making too much of all this?
    Thanks
    Martin

    First of all, stay away from spaces in file names AT ALL COST.
    The examples you cited would look like:
    alt="Oil%20on%20Canvas:%20Cattle%20on%20a%20Hill" or
    alt="Cattle%20on%20a%20Hill" or
    alt="A%20group%20of%20cows%20grazing%20in%20pasture%20under%20moonlight."
    to an SE crawler.
    If you really want effective picutres, use Photoshop or Fireworks to embed metadata and THEN add them to your site.
    Alt tags means the text that would appear if the image didn't for some reason. It also helps with accessibility for visually impaired viewers who use plug-ins to allow their browser to "speak" the images to them when the page loads.
    <img src="img/example-1.jpg" width="128" height="160" alt="example-1.jpg" />
    Above is an example of how to add alt text. Dreamweaver actually loads the alt tag automatically unless you've turned it off somehow.
    Either put the info in the Alt box in the properties panel, or in code view, add it between the quotes.
    To the second part of your question, Alt tags are meant for SEO with the images only (Like when you search for images of a certain name or containing certain tags)
    and really have little effect on the page SEO itself. For that type of optimization you want Keywords, and Descriptors in the <head> portion of the
    individual page:
    <meta name="google-site-verification" content="Optimizer code would go here" />
    <meta name="Description" content="Page name, site name, business name, location, phone number, etc. goes here"/>
    <meta name="Keywords" content="Restaurant, Sports bar, Catering, Hotel, Gallery, Car Dealer, Exterminator or whatever describes the site and page as well as content of the pages"/>
    <meta name="author" content="your name here"/>
    <meta name="robots" content="index, follow"/> (This tells search engine crawlers to index this page and each one you add it to,  and follow them site wide)
    <meta name="revisit-after" content="7 days"/> (This tells the crawler when to revisit for updates after it has indexed the site)
    To your last question. No, you're not making too big a deal out of it, if you're talking about exposure for a business. If it's a personal gallery of your favorite vacation pictures? You just might be.

  • I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    I need to reinstall my operating system for 10.5 after seeing a file folder and question mark flashing on my start up screen. Can anyone help me with this?

    Hello,
    That means it can find the Hard Drive, or can't find the things needed for booting.
    See if DU even sees it.
    "Try Disk Utility
    1. Insert the Mac OS X Install disc, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu at top of the screen. (In Mac OS X 10.4 or later, you must select your language first.)
    *Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.*
    3. Click the First Aid tab.
    4. Select your Mac OS X volume.
    5. Click Repair Disk, (not Repair Permissions). Disk Utility checks and repairs the disk."
    http://docs.info.apple.com/article.html?artnum=106214
    Then try a Safe Boot, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, reboot when it completes.
    (Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.)

  • Protecting file/folder names/labels

    Anyone know of a way to protect, lock or "freeze" file/folder names/labels without locking the associated file or folder?
    Thanks,
    JD

    You cannot do that without changing certain permissions on the files. You can remove write permissions on the files, but then you wouldn't be able to make any changes to them, if you needed to, without restoring write permissions.
    Perhaps if you tell us why you've asked about this we could offer some additional ideas, if any.
    +BTW, you've posted in the Snow Leopard forum but your profile shows a G5 running Leopard. We appreciate it if you would post questions in the correct forums. This would be the wrong forum for your question based on your profile.+
    Message was edited by: Kappy

  • Keyboard not working (sometimes) when attempting to change file/folder name

    Every now and then, my keyboard doesn't seem to work when I'm trying to change the name of file or folder. I can't isolate any particular context when this occurs. When it happens, the keyboard works fine in other applications.
    Any ideas on why this happens?

    Here's a description of what happens. Let's say I want to change the name of a file or folder on my desktop. I click the item, then the name, and the name becomes editable. Every now and then, even though the file/folder name is in the edit mode (highlighted or cursor inserted), when I try to type nothing happens (the name doesn't change). When this occurs, the keyboard functions properly in all other ways.
    Again, I can't isolate the circumstances leading up to this. Any ideas?

  • Script for Batch Exporting XML from IDCS3 files

    Does anyone have a script they would share for batch exporting XML from IDCS3 files? I do not know anything about scripting so I do not know how to write one myself. I've also searched around and cannot find anything. I would appreciate any help with this anyone can offer.
    Thanks,
    Janine

    Or use below Code:
    try {
         inFolderName= Folder.selectDialog ("Input Folder:");
         outFolderName= Folder.selectDialog ("Output Folder:");
         if ((inFolderName != null) && (outFolderName != null))
              var idFileFolder = new Folder(inFolderName);
              var files = idFileFolder.getFiles("*.indd");
              for(myCounter = 0; myCounter < files.length; myCounter++)
                   var theDocument = app.open(File(files[myCounter]));
                   with ( theDocument ) {
                   myXMLFile = new File(outFolderName + "/" + name.replace(".indd","") + ".xml" );
                   exportFile( ExportFormat.xml, myXMLFile );
                   close(SaveOptions.no);
    catch (err ) {
    alert("All files export");
    Shonky

  • Apple script to replace content in specific folders with folder names in csv

    Can anyone please help me with this scenario... It would greatly be appreciated!
    1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
    2. I have 100 folders named the same as Column 1.  in each folder there is different files.
    This is what I need.
    I need the script to to find the folder based upon column 1.
    Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2.  There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
    Then same for column 3 find place holder named Entry B and replace.
    Then it should save all files.
    Any help is greatly appreciated!  Thank you!

    Can anyone please help me with this scenario... It would greatly be appreciated!
    1. I have a list in csv containing 3 columns: Column 1 = Folder name • Column 2 = Entry A • Column 3 = Entry B
    2. I have 100 folders named the same as Column 1.  in each folder there is different files.
    This is what I need.
    I need the script to to find the folder based upon column 1.
    Then the script should search for place holder named "Entry A" and replace it's contents with data from Column 2.  There are several files with in the folder that contain place holder "Entry A" so it should replace it all but must remain with in that folder.
    Then same for column 3 find place holder named Entry B and replace.
    Then it should save all files.
    Any help is greatly appreciated!  Thank you!

  • Publishing bug with FTP servers - Spaces at end of file/folder names

    I'm sharing what I've found after lots of troubleshooting with my Mom's iWeb website. I originally came across this in the previous version of iWeb, and have seen it again in the current version.
    For the sake of this example, she had an image gallery on her site. The image file she added to iWeb had a space at the of the filename, just before the file extension, something like "image name .jpg"
    In the old version of iWeb (iWeb 08), we would publish the site to a folder on her computer, and it would generate a folder for each image in the gallery. These folders would hold the original image and thumbnail image. Each folder name was the image's filename, minus the extension. In this example, the folder name was "image name " with a space at the end, which is valid on the Mac OS X file system.
    When we uploaded it to the FTP site (which happened to be GoDaddy) using a 3rd party FTP tool, certain images would always fail to upload. After much testing and troubleshooting with other FTP software, we found that the FTP server did not allow spaces at the end of folder names, and it automatically replaced them with underscores. So, we tried to upload a folder called "image name ", and ended up with one called "image name_". As a result, we couldn't upload any of the files that were supposed to be IN that folder, because it could not be found under it's intended name.
    Fast forward to today, using iWeb 09. Now the software allows you to upload to a 3rd party FTP server, so we've stopped using the other FTP software and do it all in iWeb.
    She added a new image to her gallery and tried to publish changes, and got the error: "There was an error communicating with the FTP server. Try again lager, or check with your service provider"
    Once she removed the image, publishing worked again. It turned out the original image had a space at the end of the filename, just before the extension again. Once this space was removed, everything worked again.
    Hopefully this helps somebody else down the road. If you have trouble with certain files, check them for spaces at the end, just before the extension. Perhaps in a future release, Apple could update the site publishing code to trim leading/trailing spaces from folder names.
    If you've seen this before, or have any further questions/feedback for me, feel free to post a response. Thank you for reading.

    It would be nice if Apple could make their error messages more descriptive of the actual problem so we have a better idea of how to solve it. I am "the mom" who had the problem B2Ben posted about.
    The error message seemed to place blame on the ftp server or my ISP, consequently I wasted a lot of time with these people when it wasn't even remotely their fault.
    As with most computer problems, I ended up learning a lot from it and it always helps with gaining confidence. This is my 20th year as a Mac user!.. yes, since 1989. I look forward to seeing what some of you have experienced with this same issue.
    iMac GHZ PowerPC G$ Mac OS X (10.5.7)

  • Possible: renaming files - folder names as variables.

    Here's a bit of background - I have a rather extensive MP3 collection (all legal - I work for an independent music magazine in my spare time) - it's approx 7,000 files big now.
    I have them all stored in folders as follows:
    c:\SAMag\MP3's\Albums (and here comes the tricky bit...)
    EITHER
    \Artist Name Here - Album Title\<.MP3 files here> (No artist names contain a '-' so this is the seperator)
    OR
    \Artists Name Here\Albums Title One\<.MP3 files here>
    \Artists Name Here\Albums Title Two\<.MP3 files here>
    \Artists Name Here\Albums Title Three\<.MP3 files here> (Where there are more than one albums to an artist)
    Playing these files is a nightmare as they all have different naming conventions and odd ID tags. I want to remove all ID tags and rename them to have meaningful file names (so that WinAmp displays a decent, non-confusing, name).
    I would like:
    "<artist name> - <song title> (<album title> - <#>)"
    So, basically - is it possible to rename files in Java. Specifically: using the folder names that they are contained in as variables to put in this name?
    Thanks for any help people!

    Thanks for that.
    I'm pretty new to this whole Java thing (even though
    I've been attempting to do it for a while!) so was
    wondering if you could point me in the right
    direction.
    That is exactly what I did though.
    Do you have the javadocs? If so then you look up java.io.File and read the methods in it.
    Here is the online link....
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

  • Strange character at the end of some file/folder names

    I'm getting a strange character at the end of some of my file and folder names. This is it:  When I enlarge it, it says "private use" on the top and bottom, "E000" on the left side, and "F8FF" on the right side. It acts like a character within the font, but I'm not sure why it's there.
    In case that didn't work, I'm going to try to attach or embed a gif of the character. I'm not sure if it will work or not.
    Also, some longer file names seem to be dleeting some of the letters and are inserting a pound sign and a few numbers (e.g. #34) in place of the letters.
    What's going on?
    As usual, thanks in advance,
    Lloyd

    I thought that might be it...at first. Then I found some file names that were nowhere near 32 characters long whose names were truncated.
    It's not a huge problem, except in QuarkXPress when I collect the files for output and I have to reconnect to the ones whose names have been changed (to protect the innocent, I suppose).
    Thanks for the input mark.
    Lloyd

  • Time Machine v.1 lost file folder names all the way back to "the beginning of time"

    I was experiencing some increasingly erratic system problems with my White 2006 iMac running OS 10.5.8. My guess is that these problems were due to power outages cutting power to the iMac while it was in use.
    - I tried Disk Utility from the Install Disk and it cleaned the HD but when I ran Verify Disk from Disk Utility off the HD it reported errors and I continued having problems.
    --  I decided to wipe the HD and reinstall everything.
    --- The first thing I did was backup with Time Machine v.1 and then disconnect the backup drive.
    ---  After reloading the OS and upgrades I ran Verify Disk from Disk Utility off the HD and it reported no errors.
    ----   Skipping all the headache a reinstall entailed ... I reloaded my files from the external backup drive Time Machine backups by grabbing the folders and pulling them to the cleaned HD.
    -----     I found large portions of files names missing. They look to be exclusively file names starting with a number that I use to order files ( 01. , 02. , 03. ... etc) as opposed to alphabetical listing.
    -----     These files - so far - are all located on a single folder branch. Meaning: as I follow the folder tree down I get to a list of project folders and some or all are missing everything but the starting number. I wrote this off as something to do with the hard drive operation problem but ...
    ------      ... all the same backup folders in Time Machine on my Seagate GoFlex have also lost their names all the way back for 2 years, when I started using Time Machine and the GoFlex.
    ------      I know for a for a fact the folder names were intact before I cleaned the iMac HD since I regularly use those files.

    They aren't what they appear to be on the TM, most are aliases to aliases to aliases when files are changed, I think only TM understands how/where the files are actually stored.
    Later versions of the OS with Restore Partitions can Restore also
    Do run DU on the TM drive... it certainly can't hurt at this point.
    I recommend cloning your drives instead of TM, not only can you copy files/folders over if needed, you can actually boot from your backup & continue working, or even clone back to the Internal...
    Get carbon copy cloner to make an exact copy of your old HD to the New one...
    http://www.bombich.com/software/ccc.html
    Or SuperDuper...
    http://www.shirt-pocket.com/SuperDuper/
    Or the most expensive one & my favorite, Tri-Backup...
    http://www.tri-edre.com/english/tribackup.html

  • A script for adding the current date to file name?

    I am working in Indesign CS3. I frequently save file as PDFs into a designated folder. I was hoping for help in writing a script that would apply the current date to the end of the file name, when saved into this folder. Some days, I save the same file several times, into this folder. I was also hoping there was a way to add a date and version, for example "filename_2.25.11(1).pdf" Is this possible? Can someone help me?

    ok, I ended up with this test routine:
    on adding folder items to this_folder after receiving added_items
    tell application "Finder"
    repeat with this in added_items
    my checkifopened(this)
    display dialog (name of this) as text
    end repeat
    end tell
    end adding folder items to
    on checkifopened(this)
    set a to POSIX path of (this as alias)
    repeat until 1 = 0
    ## don't like that one because it relies on an error msg ... so
    (** try
    set b to do shell script "lsof | grep " & quoted form of a
    on error
    exit repeat
    end try**)
    ##so I use this one
    set b to do shell script "lsof"
    if b does not contain a then
    exit repeat
    else
    say "still opened"
    end if
    end repeat
    end checkifopened
    this is a folder action that tests if the added file is still opened by an application... there is no delay between each test-loop since lsof takes some time to execute...
    And after adding a timeout (just in case) to this function the final script looks like this:
    on adding folder items to thefolder after receiving added_items
    tell application "Finder"
    set folderkind to kind of thefolder
    set myfiles to every item of thefolder whose name does not contain "#" and kind is not folderkind
    repeat with myfile in myfiles
    set myfile_datestring to my get_datestring(creation date of myfile)
    set myfilename to name of myfile
    if (count of every character of myfilename) > 4 and (character -4 of myfilename) as text is "." then
    set filestatus to my checkifopened(myfile, 60)
    if filestatus = false then
    display dialog "timeout on folder action"
    else
    set tmp to ((characters 1 through -5 of myfilename) & "#" & myfile_datestring & (characters -4 through -1 of myfilename)) as text
    set myfilename to my checknamewith_pdfsuffix(tmp, thefolder, false)
    set name of myfile to myfilename
    end if
    end if
    end repeat
    end tell
    end adding folder items to
    on get_datestring(mydate)
    return year of mydate & "-" & (characters -2 through -1 of (("0" & (month of mydate as integer)) as text)) & "-" & (characters -2 through -1 of (("0" & (day of mydate as integer)) as text)) as text
    end get_datestring
    on checknamewith_pdfsuffix(n, D, looped)
    --check if filename exists in D
    -- so if "A File.pdf" exists it names it "A File 1.pdf","A File 2.pdf",...
    #n = string of the filename
    #D = file reference to the directory to check
    #looped = boolean used for recursive loop...
    tell application "Finder"
    set thefiles to name of every item of (D as alias)
    end tell
    if thefiles contains n then
    if looped = false then
    set n to ((characters 1 through -5 of n) & "(1)" & (characters -4 through -1 of n)) as text
    my checknamewith_pdfsuffix(n, D, true)
    else
    set tmp to (last word of ((characters 1 through -5 of n) as text) as integer)
    set tmpcount to (count of characters of (tmp as text)) + 5
    set tmp to tmp + 1
    set n to ((characters 1 through (-1 * tmpcount) of n) & "(" & tmp & ")" & (characters -4 through -1 of n)) as text
    my checknamewith_pdfsuffix(n, D, true)
    end if
    else
    return n
    end if
    end checknamewith_pdfsuffix
    on checkifopened(this, mytimeout)
    ## this file reference
    ## timeout in seconds
    set a to POSIX path of (this as alias)
    set startdate to current date
    repeat until 1 = 0
    ## don't like that one because it relies on an error msg ... so
    (** try
    set b to do shell script "lsof | grep " & quoted form of a
    on error
    exit repeat
    end try**)
    ##so I use this one
    set b to do shell script "lsof"
    if b does not contain a then
    return true
    else if ((current date) - startdate) > mytimeout then
    return false
    else
    ##say "still opened"
    end if
    end repeat
    end checkifopened
    to use this save this script in /Library/Scripts/Folder Action Scripts
    and add this as a folder action to your folder...
    The script processes all files inside that folder each time a new files is added...

  • Need Help with scripting for Automator/AppleScript.

    Hi everybody,
    I am building a small app for my mac, What I need is a script that can rename a file that I drop on it.
    and example being:
    example.jpg
    (when I drop it on the app, I want the app to change the filename of the document to "Image.jpg"
    I have tried this with Automator, but it requires that I specify the file to be changed, what I need is something that will change the name of any file I drag onto it.
    I am using it for application specific files.
    Kind regards,
    Pete.
    iBook G4; 60GB Hard Drive, 512MB RAM, Airport Extreme    

    Open the Script Editor in the
    /Applications/AppleScript/ folder and enter the
    following:
    on open(the_file)
    tell application "Finder"
    set name of the_file to "Image"
    end tell
    end open
    Save this script as an application.
    (11347)
    this script compiled correctly; however when run it returned the following error "Can't set name of (the_file) to "Image.jpg"
    I am also given the option of editing the script or just quitting.
    thanks for your help

  • Automator problem - Send text from file to email

    Hi all, I used automator on OsX 10.6 to send automatically the text within an HTML file to an email and then to a list of addresses. I installed 10.7 and now the thing doesn't work anymore.
    I did a couple of tests and it looks like the text taken from the file doesn't pass to the email body. Do you have any clue on how to do this?
    Thanks

    Hi,
    Print the whole stack trace. It will tell you the line which causes the error. How you use clob and blob in oracle is also version dependent. Try to google for
    oracle "your version" java clob example.
    /Kaj

Maybe you are looking for

  • Preferences Errors and Lots of software crashes...

    Heys, I am very new to this forum, so if this is in the wrong place I apologize! I have a White MacBook (plastic cover, not aluminum or pro) that I bought in 2008, stupidly, I never got time machine up and running on it. I recently switched to a newe

  • File Receiver Adapter(File Content Conversion)

    Hi All, If i open my file using notepad after File Content Conversion i am seeing a BOX kind of Symbol after Every Row .. but the same file if i open using word i am not seening that BOX ,,and the file is perfect ..can any plz tell what is the reason

  • IMac G5 Shuts down while running applications

    I installed iLife '06. Since then my iMac G5 (20") has started shutting down while I'm working. I'm not sure if the installation is related to the intermittent shut down or if there is another problem. Someone told me that the fan might be bad. I don

  • Iphoto won't open after changing from os10.5 to os10.4

    hello there last night i reinstalled os10.4. i have been running leopard, but a program that i want to use is not yet compatible with it. after installing it, it put all of my documents/files in a folder called 'previous system' on my hard drive. i t

  • Error code 104 while installing updates to mountain lion?

    I am trying to perform the latest update of mountain lion, which consists of an iMovie and Java update, and I am recieving an error notice (104), saying that another update is already taking place. Oddly enough, when I went to add/remove programs in