Hello all,
I have a problem with my script and i just can’t seem to find the answer. Currently trying to convert many files from .xls to csv and would like to set this up as a folder action. Saying that i can also run it through cron and set to repeat at whatever time I see fit. But the only way I can get this to work is to set the “prompt for” folder up (but that needs to be done manually. So, here is what works:
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)
if ((name of item i of theFiles) as text) ends with “.xls” then
set tName to (theFolder as text) & fName & “.csv”
tell application “Microsoft Excel”
activate
open (item i of theFiles) as text
save fName in tName as CSV
close active workbook without saving
end tell
end if
end repeat
AND, here is what does not work:
set theFolder to “Users/somefolder/somefolder”
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)
if ((name of item i of theFiles) as text) ends with “.xls” then
set tName to (theFolder as text) & fName & “.csv”
tell application “Microsoft Excel”
activate
open (item i of theFiles) as text
save fName in tName as CSV
close active workbook without saving
end tell
end if
end repeat
Thanks,
tringo