我不知道理解你想與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