excel - Trying to Use AppleScript to Convert .xls and .xlsx to .txt (Tab Delimited), Needs Fixing -
i copied answer got thread. trying convert ~300 .xls , .xlsx files tab delimited. in same folder. if knows better way, please let me know.
property type_list : {"xls6", "xls7", "xls8", "xlsx"} property extension_list : {"xls", "xlsx"} on open these_workbooks repeat k 1 count of these_workbooks set this_item item k of these_workbooks set item_info info this_item --this if statement tests make sure items you're converting excel spreadsheets , not folders or aliases if (folder of item_info false) , (alias of item_info false) , ((the file type of item_info in type_list) or name extension of item_info in extension_list) tell application "finder" open this_item tell application "microsoft excel" --this tacks on ".txt" file name set workbookname (name of active workbook & ".txt") --save current open workbook tab-delimited text file tell active workbook save workbook 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 icon." end run
all open dialog box , nothing. though it's meant droplet, nothing happens when drag file it.
in applescript run
handler gets run when script or application run normally. meanwhile, open varname
handler gets run when file or files dropped onto icon of application , files set variable varname
. script posted cleverly places display dialog
in on run
handler try understand usage. instead, save script application , drop files onto it.
edit:
after quick test on mountain lion machine has excel 2011 (i didn't realize how i'd been overcomplicating):
property type_list : {"xls6", "xls7", "xls8", "xlsx"} property extension_list : {"xls", "xlsx"} on open these_workbooks repeat k 1 count of these_workbooks set this_item item k of these_workbooks set item_info info this_item --this if statement tests make sure items you're converting excel spreadsheets , not folders or aliases if (folder of item_info false) , (alias of item_info false) , ((the file type of item_info in type_list) or name extension of item_info in extension_list) tell application "finder" open this_item tell application "microsoft excel" --this tacks on ".txt" file name set workbookname (path desktop string) & "after:" & (name of active workbook & ".txt") display dialog workbookname --save current open workbook tab-delimited text file tell active workbook save workbook 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 icon." end run
Comments
Post a Comment