Applescript

C

chris1982

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

Hi Eveveryone,

I'm trying to create an Applescript that converts a txt file to a csv file. I've tried all sorts of solutions but so far none have worked. My latest try is as follows:

set theFolder to choose folder with prompt "Choose the folder that contains your Excel files"
tell application "Finder" to set theFiles to (files of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of ((name of item i of theFiles) as text)
set tName to (theFolder as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
open text file filename (item i of theFiles) data type delimited origin MSDos with consecutive delimiter and space without tab
save fName in tName as CSV Windows file format
end tell
end repeat

Right now when I run the script nothing happens after I choose the folder. I have to use all the parameters after open text file because of the type of file I'm opening.

Anyone's help would be greatly appreciated.
 
J

JE McGimpsey

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel
Right now when I run the script nothing happens after I choose the folder. I
have to use all the parameters after open text file because of the type of
file I'm opening.

This works for me:

tell application "Finder"
set theFolder to choose folder with prompt ¬
"Choose the folder that contains your Excel files"
set theFiles to (files of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of ¬
((name of item i of theFiles) as text)
set tName to (theFolder as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
open text file filename (name of item i of theFiles) data
type delimited origin MSDos with consecutive delimiter and space without
tab, other char, semicolon and comma
save fName in tName as CSV Windows file format
end tell
end repeat
end tell
 
C

chris1982

Hmmm...when I try too run this I get an error message "Can't continue said:
This works for me:

tell application "Finder"
set theFolder to choose folder with prompt �
"Choose the folder that contains your Excel files"
set theFiles to (files of theFolder)
set fileCount to count theFiles
repeat with i from 1 to fileCount
set fName to text 1 thru -5 of �
((name of item i of theFiles) as text)
set tName to (theFolder as text) & fName & ".csv"
tell application "Microsoft Excel"
activate
open text file filename (name of item i of theFiles) data
type delimited origin MSDos with consecutive delimiter and space without
tab, other char, semicolon and comma
save fName in tName as CSV Windows file format
end tell
end repeat
end tell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top