2013-08-15 4 views
1

Я скопировал это из ответа, полученного из другого потока. Я пытаюсь преобразовать файлы ~ 300 .xls и .xlsx в разделитель табуляции. Все они находятся в одной папке. Если кто-нибудь знает лучший способ, пожалуйста, дайте мне знать.Пытается использовать AppleScript для преобразования .xls и .xlsx в .txt (вкладка с разделителями), требуется фиксация

property type_list : {"XLS6", "XLS7", "XLS8", "XLSX"} 
property extension_list : {"xls", "xlsx"} 


on open these_workbooks 
repeat with k from 1 to the count of these_workbooks 
    set this_item to item k of these_workbooks 
    set the item_info to info for this_item 

    --this if statement tests to make sure the items you're converting are Excel spreadsheets and not folders or aliases 
    if (folder of the item_info is false) and (alias of the item_info is false) and ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then 

     tell application "Finder" to open this_item 

     tell application "Microsoft Excel" 
      --this just tacks on ".txt" to your file name 
      set workbookName to (name of active workbook & ".txt") 
      --save the current open workbook as a tab-delimited text file 
      tell active workbook to save workbook as filename workbookName file format text Mac file format 
      close active workbook saving no 
     end tell 
    end if 
end repeat 
end open 

on run 
    display dialog "Drop Excel files onto this icon." 
end run 

Все это открывает диалоговое окно и ничего не делает. Несмотря на то, что он предназначен для капли, ничего не происходит, когда я перетаскиваю файл на него.

+1

Этот сценарий используя «Капли» (http://macscripter.net/viewtopic.php?id=24772). Сохраните его как исполняемое приложение и затем отбросьте на него файлы (вот что говорит этот диалог) – scohe001

ответ

3

В Applescript обработчик run запускается, когда сценарий или приложение запускаются нормально. Между тем, обработчик open VarName запускается, когда файл или файлы dropped onto the icon приложения и файлы устанавливаются в переменную VarName. Сценарий, который вы разместили, удачно размещает display dialog в обработчике on run, чтобы помочь вам понять это использование. Вместо этого сохраните скрипт как приложение, а затем отбросьте на него файлы.

EDIT:

После быстрой проверки на машине Mountain Lion, который, наконец, имеет Excel 2011 (я не понимал, насколько я был усложнять):

property type_list : {"XLS6", "XLS7", "XLS8", "XLSX"} 
property extension_list : {"xls", "xlsx"} 


on open these_workbooks 
    repeat with k from 1 to the count of these_workbooks 
     set this_item to item k of these_workbooks 
     set the item_info to info for this_item 

     --this if statement tests to make sure the items you're converting are Excel spreadsheets and not folders or aliases 
     if (folder of the item_info is false) and (alias of the item_info is false) and ((the file type of the item_info is in the type_list) or the name extension of the item_info is in the extension_list) then 

      tell application "Finder" to open this_item 

      tell application "Microsoft Excel" 
       --this just tacks on ".txt" to your file name 
       set workbookName to (path to desktop as string) & "After:" & (name of active workbook & ".txt") 
       display dialog workbookName 
       --save the current open workbook as a tab-delimited text file 
       tell active workbook to save workbook as filename workbookName file format text Mac file format 
       close active workbook saving no 
      end tell 
     end if 
    end repeat 
end open 

on run 
    display dialog "Drop Excel files onto this icon." 
end run 
+0

Удивительный! Благодаря! Есть ли что-нибудь, что я могу добавить в сценарий для экспорта в другую папку? Также, как изменить имя файла, чтобы избавиться от расширения .xls.txt и просто изменить его на .txt? –

+0

@Jart Я только что отредактировал его. – scohe001

+0

Так что это в основном извергало все на моем рабочем столе с именами файлов «Документ 1», «Документ 2» и т. Д. Есть ли способ указать конечный пункт вывода для целой группы файлов, сохраняя свои первоначальные имена? –

Смежные вопросы