我不知道理解你想与textWrangle做什么,但脚本波纹管完成所有步骤之前和之后,只有使用AppleScript(无需Automator动作):
--this choose file must be replaced by your "input" of automator folder items
set Fxl to choose file --the Excel file to be processed
-- define here your destination SQL folder
-- for my tests, I used a folder mySQL on my Desktop
set SQLFolder to ((path to desktop folder) as string) & "mySQL"
tell application "Finder" to set ForSQL to (container of Fxl) as string
--define new name by replacing current extension (xls, xlsx, xlsm, xml) by "csv"
tell application "Finder"
set N to name of Fxl
set NbExt to length of ((name extension of Fxl) as string)
set newname to (text 1 thru -(NbExt + 1) of N) & "csv"
end tell
--convert to CSV and close
tell application "Microsoft Excel"
open Fxl
tell workbook 1
tell sheet 1 to save in (ForSQL & newname) as CSV file format
close without saving
end tell
end tell
-- add eventually your TextWrangle step here (?)
-- delete source file and move csv to proper folder
tell application "Finder"
delete Fxl
move file (ForSQL & newname) to folder SQLFolder
end tell
在实践中,你可以完全的AppleScript文件夹操作运行的这一切。 通过“添加文件夹项目...”替换“设置Fxl以选择...”。 在这种情况下,您必须在重复循环中插入上述脚本来处理文件夹中的所有文件丢失。
但是,使用文件夹操作脚本时可能会遇到一些问题,因为系统会在创建新CSV文件时再次触发脚本(同样在同一文件夹中!)。
我建议的解决方法是使用文件夹操作脚本来将文件放到ForSQL中,将其移动到其他“temp_ForSQL”并使用移动的文件运行此脚本。这样做,CVS将被添加到temp_forSLQ,而不会触发新的文件夹操作脚本。
我希望它已经够清楚了......如果没有,请让我知道。
非常感谢!试图跟随和测试出来。我是否应该不再使用automator文件夹操作 - 如果没有,我必须在事件命中我的Downloads文件夹时添加'添加文件夹项目'。另外,由于我们在同一个文件夹中创建了CSV,有没有办法在转换之前将文件移动到SQL文件夹,这样就不会发生?最后,我还没有得到这个工作,但Automator脚本的主要问题是,从Excel 2016 for Mac中弹出的“授予访问”页面,导致整个事件中断。这是否与此代码一起? – Ryan
此外TextWrangler部分只是为了确保文件保持在UTF-8中,因为我注意到其中一些由于某种原因正在更改为OS Roman。但是,如果这可能发生在Excel中,那么我不会需要这一步 - 只是无法找到任何其他方式。 – Ryan
一直在玩这个和我不断收到错误“错误”Microsoft Excel得到一个错误:参数错误。“数字-50”,当代码到'保存在(sql&newname)作为CSV文件格式'行。显然这是一个已知的问题? http://www.mac-help.com/threads/automator-wont-convert-to-csv.221267/我的Automator脚本一般工作,它只是让我手动第一次,这是毁了自动化。 – Ryan