recursion的Excel电子表格input到Applescript iMessage / SMS Messaging

好的,今天第一次和Applescript玩,6-7小时后几乎是在那里。 这个脚本的基本前提是,它应该从Excel电子表格中读取两列数据,一列是电话号码,另一列是警报。 然后它将消息写入iMessage / SMS并发送。

我已经从CSV工作,现在尝试使用源Excel文件绕过转换步骤。 我遇到了一个经典的数字格式问题,它将数字读入科学记数法并扰乱了电话号码。 把它转换回正常的stringiMessage似乎扼杀格式。 (在这一点上,我知道它简单的东西我错过了。)

set phoneCol to "O" set messageCol to "P" set startRow to 3 set endRow to 5 set xlsFilePath to (path to desktop as text) & "test.xlsx" tell application "Microsoft Excel" to open file xlsFilePath repeat with thisRow from startRow to endRow tell application "Microsoft Excel" set targetBuddyPhone to value of cell (phoneCol & thisRow) as string set targetMessage to value of cell (messageCol & thisRow) as string end tell set targetBuddyPhone to number_to_string(targetBuddyPhone) tell application "Messages" send targetMessage to buddy targetBuddyPhone of service "SMS" end tell delay 2 end repeat on number_to_string(this_number) set this_number to this_number as string if this_number contains "E+" then set x to the offset of "." in this_number set y to the offset of "+" in this_number set z to the offset of "E" in this_number set the decimal_adjust to characters (y - (length of this_number)) thru ¬ -1 of this_number as string as number if x is not 0 then set the first_part to characters 1 thru (x - 1) of this_number as string else set the first_part to "" end if set the second_part to characters (x + 1) thru (z - 1) of this_number as string set the converted_number to the first_part repeat with i from 1 to the decimal_adjust try set the converted_number to ¬ the converted_number & character i of the second_part on error set the converted_number to the converted_number & "0" end try end repeat return the converted_number else return this_number end if end number_to_string 

相比之下,从CSV中读取相同variables的以下脚本完全没有问题,我确实需要在iMessage中放置一个小的延迟或者覆盖缓冲区。

 set theFile to (choose file with prompt "Select the CSV file") -- read the file contents: set f to read theFile -- break the file into paragraphs (cf rows) repeat with row in (paragraphs of f) -- parse the row into comma-delimited fields set fields to parseCSV(row as text) -- now you have your data: set targetBuddyPhone to item 1 of fields set targetMessage to item 2 of fields tell application "Messages" send targetMessage to buddy targetBuddyPhone of service "SMS" end tell delay 2 end repeat on parseCSV(theText) set {od, my text item delimiters} to {my text item delimiters, ","} set parsedText to text items of theText set my text item delimiters to od return parsedText end parseCSV