File Batch Renaming

Discussion in 'Mac Programming' started by dlydiamg, Dec 10, 2010.

  1. dlydiamg macrumors newbie

    Dec 10, 2010
    Hi all. I'm new to this forum and extremely new to apple scripting.

    I want to set up a watched folder where it will replace part of the name of the files I'm dropping into a folder (ie. name_1up to name_3up) as soon as a new file is placed in the folder.

    I tried doing this in automator first. I saved it as a script and attached the script to the folder. It works if I hit run but it doesn't work when I drop a file in the folder. I don't want to set up something that I'd have to run every time, rather a script that would automatically rename the file,

    I saw in other forums that this can be accomplished thru applescript, possible shell script?

    Another possibility is saving the automator workflow as an app and having a folder action that triggers that app as soon as a new file is dropped in. But again, I can't find a way of doing this and I'm honestly a bit confused as to how to go about writing the action script itself.

    I saw this script in another part of this forum but was unable to make it work.

    tell application "KoLmafia"
    end tell

    I can understand that it has no even to trigger this but have no idea how to make the even or attach it to the folder

    Help anyone?

    Thanks for taking the time to read, any help will be greatly appreciated.

  2. ulbador macrumors 68000


    Feb 11, 2010
    You mention you can save it as an app. Put it in cron!

    I created a simple AppleScript and saved it as an app called "" on my desktop. With the command in the Terminal:
    /usr/bin/open /Users/adam/Desktop/

    It runs. To automate this, you need to save it to your cron

    If you open up a Terminal, type:
    touch ~/mycrontab
    open /Applications/ ~/mycrontab

    Once in this file, you'll need a line that looks something like this:
    0 * * * * /usr/bin/open /Users/adam/Desktop/

    Basically this tells cron to run this file once an hour, on the hour. You can play with the options a little bit
    * * * * * /usr/bin/open /Users/adam/Desktop/ #Every minute
    */2 * * * * /usr/bin/open /Users/adam/Desktop/ #Every two minutes
    0 15,22 * * * /usr/bin/open /Users/adam/Desktop/ #3pm and 10 pm, on the hour
    0 * * * sun,thu /usr/bin/open /Users/adam/Desktop/ #Every Sunday and Thursday, on the hour

    Basically, once you find the frequency you want, save the file. Then, back in the terminal:

    crontab ~/mycrontab

    This installs the file you just created.
  3. dlydiamg thread starter macrumors newbie

    Dec 10, 2010
    Thanks for the reply but I don't think that's what I need. I will need to use this on a server also, not locally.

  4. ianray macrumors 6502

    Jun 22, 2010
    Hi, I was curious -- so I did this:

    1. New Folder "dropee" on desktop
    2. Open Automator, New Folder Action
    3. Drag "dropee" to the 'Folder Action receives files and folders added to' folder
    4. Add action 'Rename Finder Items'
    5. Select 'Replace Text' from the drop-down box
    6. Find: XXX, Replace: YYY
    7. Save
    8. Drag files named oneXXX.txt, XXXtwo.txt, thrXXXee.txt, and four.txt to dropee folder

    The result was that oneXXX.txt and XXXtwo.txt were correctly transformed to oneYYY.txt and YYYtwo.txt, but thrXXXee.txt was not changed.

    Is this the problem that you are having?

Share This Page