背景:我試圖使用其AllShare功能將來自電話應用程序(電話Amego)的來電者信息傳遞給我的三星電視。爲了做到這一點,我必須發送帶有來電者信息的肥皂訊息。電話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,但我應該從電話Amego通過處理程序call_from(callerID_string)獲得它。但無論我嘗試什麼,我都無法將該callerID_string傳遞給我的代碼。它由2部分組成,即呼叫者的姓名和號碼。代碼應該像這樣開始:
on call_from(callerID_string)
任何幫助將不勝感激。
歡迎您!感謝您的反饋。請注意,如果解決了問題,通常會接受答案。 – 2013-04-21 17:14:02
對不起,在此期間不知道。我在這裏也是一個新手。親切的問候。渣子 – user2303065 2013-04-21 23:13:32