5 Replies Latest reply: May 15, 2013 1:54 PM by marcosfromnull
DK Deadhead Level 1 Level 1 (0 points)

Hi!

 

I hope there is someone who can help me. I have very little experience with Applescript, and have spent a couple of days scouring these forums amongst others without any luck...

 

I have a folder (titled XLS) with about 1000 excel files in it. They are numbered basen on some parametric calculations (1111.xls, 1112.xls, 1113.xls, etc). I have constructed an Automator rutine which, one at a time, can open each excel file, copy some cells and then paste the data into an empty xml-file in TextWrangler. The empty xml-file is also in the XLS folder.

 

What I am looking for is an applescript which can rename the open xml-file with the same filename as the xls-file. So, when 1111.xls is open, the xml-file gets renamed 1111-xml; when 1112.xls is open, the xml-file gets renamed 1112-xml, etc. Each new xlm-file is to be saved into a folder XLM, whivh is also in the XLS folder.

 

Thanks in advance....

 

Rob


MacBook Pro, OS X Mountain Lion (10.8.2), Mac user since 1993
  • 1. Re: Help with Applescript - filenames
    pjdube Level 3 Level 3 (830 points)

    You don't necessarily need applescript for that. Why don't you tell me what you automator workflow is and then I can help you be able to name these files correctly.

     

    Regards,

     

    Phil

  • 2. Re: Help with Applescript - filenames
    DK Deadhead Level 1 Level 1 (0 points)

    Hi Phil

     

    I solved it with an little AppleScript I found on the net!

     

    Rob

  • 3. Re: Help with Applescript - filenames
    marcosfromnull Level 1 Level 1 (0 points)

    Can you share the sample script for this?

     

    Re: Help with Applescript - filenames

     

     

     

    Hi Phil

     

    I solved it with an little AppleScript I found on the net!

     

    Rob

  • 4. Re: Help with Applescript - filenames
    DK Deadhead Level 1 Level 1 (0 points)

    Se below; there are two folders on the desktop; "xls" (with xls-files in) and "xml", as well as the empty Template.xml file. Here it is!:

     

      --3 XLS to XML

     

              tell application "Finder"

                        set fileList to every file of entire contents of ("YourHD:Users:You:Desktop:xls" as alias)

              end tell

     

     

              repeat with i from 1 to number of items in fileList

                        set currentFile to (item i of fileList)

     

                        tell application "Microsoft Excel"

                                  set screen updating to false

      open currentFile

      activate currentFile

      activate object worksheet 1

                                  copy range range ("YourRange")

                        end tell

     

                        tell application "Finder"

                                  copy file "YourHD:Users:You:Desktop:Template.xml" to folder "YourHD:Users:You:Desktop:xml"

                        end tell

     

                        tell application "Microsoft Excel"

                                  set docName to name of window 1

                        end tell

     

                        tell application "Finder"

                                  set docName2 to text 1 thru ((offset of "." in docName) - 1) of docName

                                  set theFile to "YourHD:Users:You:Desktop:xml:Template.xml" as alias

                                  set the name of theFile to docName2 & ".xml"

      open file theFile

                        end tell

     

                        tell application "TextWrangler"

      activate

      paste

      close text document 1 saving yes

                        end tell

     

                        tell application "Microsoft Excel"

      activate

      close active workbook saving no

                        end tell

              end repeat

     

     

              tell application "Microsoft Excel"

                        set screen updating to true

      quit

              end tell

     

              tell application "TextWrangler"

      quit

              end tell

  • 5. Re: Help with Applescript - filenames
    marcosfromnull Level 1 Level 1 (0 points)

    Thank you