need help with script

Discussion in 'Mac Programming' started by Marsheezi, Jun 28, 2007.

  1. macrumors newbie

    Apr 8, 2005
    okay i've been looking around and i think its possible, but not sure. hopefully somebody can help me out.

    let say i have about 5000 files. all with the name scheme:

    10482 Something.jpg
    49230 Whatever.jpg
    12301 Pleasehelpme.jpg

    is there a script that can take the numbers that exist in the first part of the filename and remove the remaining characters from the filename?

    10482 Something.jpg ----> 10482.jpg
    49230 Whatever.jpg -----> 49230.jpg
    12301 Pleasehelpme.jpg ------> 12301.jpg

    the numbers aren't sequential so none of the renaming tools i found can help, and the number of characters after the numbers isnt contant so just chopping off several characters before the file extension wont help.

    thanks in advance
  2. macrumors 68040


    Sep 13, 2003
    Its not so much where you are as when you are.
    tell application "Finder"
    set aList to every file of folder (choose folder)
    repeat with anItem in aList
    set aName to name of anItem
    set aName to word 1 of aName&".jpg"
    set name of anItem to aName

    /money for nuttin'
    //Scripts for free

Share This Page