Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Operating System (http://www.mac-forums.com/forums/os-x-operating-system/)
-   -   Applescript troubleshooting (http://www.mac-forums.com/forums/os-x-operating-system/243884-applescript-troubleshooting.html)

TSMIIINOLA 07-13-2011 09:51 AM

Applescript troubleshooting
 
I have a folder of 258 excel files that are sorted alphabetically. I would like to run a script that renames all of the files based on excel values. I wrote a script that does a similar action, but to add new folders based on excel content. I tried to adapt it, but I was unsuccessful. Can anyone help?

vansmith 07-13-2011 09:57 AM

Can you post the script? It's likely that it can be adapted with some minor changes.

TSMIIINOLA 07-13-2011 10:01 AM

set theFiles to choose file with multiple selections allowed
set theCount to number of items in theFiles
repeat with i from 1 to theCount
tell application "Microsoft Excel"
set theCells to value of range "a1:a71" of active sheet
end tell
repeat with onecell in theCells

tell application "Finder"


set name of file (item i of theFiles) to (item 1 of onecell)

end tell
end repeat
end repeat

MacGrunt 08-02-2011 08:20 AM

G'day

I'm assuming you are trying to rename a bunch of files using one open excel spreadsheet as the source of the filenames and that the new filenames are in column A (?)

Code:

set theFiles to choose file with multiple selections allowed
set NewNames to {}

--place enough values from excel file into a list
tell application "Microsoft Excel"
        tell active sheet of active workbook
                repeat with x from 1 to count of theFiles
                        set end of NewNames to formula of cell ("A" & x)
                end repeat
        end tell
end tell
--rename the files
repeat with i from 1 to count of theFiles
        set NewName to item i of NewNames
        set ThisFile to item i of theFiles
        tell application "Finder"
                set name of ThisFile to (NewName & "." & name extension of ThisFile)
        end tell
end repeat

i haven't tested what will happen if the script runs into an empty cell.

you could also run this as a droplet instead by changing it like this :
Code:

on open theFiles
        -- delete the following line
        set theFiles to choose file with multiple selections allowed
        --add the rest of the script
end open

hope that helps a little

m.


All times are GMT -4. The time now is 03:37 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.