背景:我正在尝试使用其 AllShare 功能将呼叫者信息从电话应用程序 (Phone Amego) 传递到我的三星电视。为此,我必须发送带有呼叫者信息的肥皂消息。Phone Amego 提供了一种将applescript 分配给呼叫事件的简单方法。但是,我没有任何编程经验!
到目前为止,我已经成功地制作了一个脚本,它可以读取肥皂消息,更新必填字段并将其发送到我的电视。完美,至少结果,代码可能不完美,但它可以工作。这是代码。
set callerID_string to "John Doe : 1-917-123-4567"
set AppleScript's text item delimiters to {":"}
set pieces to text items of callerID_string
set callerID_name to item 1 of pieces
set callerID_number to item 2 of pieces
set AppleScript's text item delimiters to {""}
set myDate to do shell script "date '+%d.%m.%Y'"
set myTime to do shell script "date '+%T'"
set total_Length to (length of callerID_name) + (length of callerID_number) + 780
set search_strings to {"Content-Length: 796", "2013-01-01", "00:00:00", "Mike", "777-777-7777"}
set replace_strings to {"Content-Length:" & total_Length, myDate, myTime, callerID_name, callerID_number}
tell application "Finder"
set theFile to alias "Macintosh HD:Users:Marc:Desktop:IncCallMBsTemplate.txt"
open for access theFile
set fileRef to open for access (theFile as alias)
set fileContents to (read fileRef)
close access theFile
end tell
set the clipboard to fileContents
repeat with i from 1 to (count search_strings)
set the_string to the clipboard
set the_string to my snr(the_string, item i of search_strings, item i of replace_strings)
end repeat
on snr(the_string, search_string, replace_string)
tell (a reference to my text item delimiters)
set {old_atid, contents} to {contents, search_string}
set {the_string, contents} to {the_string's text items, replace_string}
set {the_string, contents} to {"" & the_string, old_atid}
end tell
set the clipboard to the_string
-- Create a file handler for the file to write to.
set myFile to (open for access alias "Macintosh HD:Users:Marc:Desktop:Test.txt" with write permission)
try
-- Delete current contents of the file
set eof myFile to 0
-- Write to file
write the_string to myFile as «class utf8»
end try
-- Close the file
close access myFile
end snr
set cmd to "/Usr/bin/nc 10.0.1.7 52235 < /Users/Marc/Desktop/Test.txt"
do shell script cmd
问题:在上面的脚本中,我为变量 callerID_string 设置了一个值,但我应该通过处理程序 call_from(callerID_string) 从 Phone Amego 获取它。但是无论我尝试什么,我都无法将该 callerID_string 传递给我的代码。它由来电者姓名和电话号码两部分组成。代码应该像这样开始:
on call_from(callerID_string)
任何帮助将不胜感激。