我有一个AppleScript脚本,可以完美地运行大多数。该脚本旨在从FileMaker中执行,从中获取信息并将消息发送到电话号码。然而,在输入电话号码之后,在10%到20%的时间内,它也会输入内容,而不是将其放在消息字段中。
这是完整的AppleScript:
set _delay to 1
set _phone_number to repetition 1 of cell "APPLESCRIPT_PIPE" of layout "DEV"
set the clipboard to _phone_number
set _msg to repetition 2 of cell "APPLESCRIPT_PIPE" of layout "DEV"
tell application "System Events"
tell process "Messages"
set frontmost to true
keystroke "n" using {command down}
delay _delay
keystroke "v" using {command down}
delay _delay
keystroke return
delay _delay
set _line_count to count of paragraphs of _msg
repeat with _line_number from 1 to _line_count
set _line to paragraph _line_number of _msg
if _line_number = _line_count then
keystroke _line
delay _delay
else if length of _line = 0 then
keystroke return using {option down}
else
keystroke _line
keystroke return using {option down}
end if
end repeat
keystroke return
end tell
end tell
正如您所看到的,我尝试使用延迟来降低错误的可能性,但它没有奏效。我开始延迟0.25秒,然后是0.5,现在是1,但它仍然在发生。
有什么建议吗?
答案 0 :(得分:1)
也许这个解决方案对你来说会更好一些,而不是涉及系统事件......
set theMessage to "Whatever Text To Send"
set thePhoneNumber to "555-555-5555" -- Any Phone Number INCLUDE THE QUOTE MARKS
-- * Other Acceptable Phone Number Formats *
-- ("1(555)555-5555","(555)555-5555", "5555555555", "15555555555")
tell application "Messages"
launch
delay 5 -- Gives Messages Time To Open (May Need To Adjust)
send theMessage to buddy thePhoneNumber of service "SMS"
end tell
如果上述解决方案不适合您,您可以直接设置值而不是使用剪贴板..就像这样......
set theMessage to "Whatever Text To Send"
set thePhoneNumber to "555-555-5555" -- Any Phone Number INCLUDE THE QUOTE MARKS
-- * Other Acceptable Phone Number Formats *
-- ("1(555)555-5555","(555)555-5555", "5555555555", "15555555555")
tell application "Messages" to activate
tell application "System Events"
delay 1 -- May Need To Adjust
click UI element "Compose" of splitter group 1 of window ¬
"Messages" of application process "Messages"
delay 1.5 -- May Need To Adjust
set value of text field "To:" of scroll area 3 of splitter group 1 of window ¬
"Messages" of application process "Messages" to thePhoneNumber
keystroke return
delay 1.5 -- May Need To Adjust
set value of text area 1 of scroll area 4 of splitter group 1 of window ¬
"Messages" of application process "Messages" to theMessage
delay 2 -- May Need To Adjust
keystroke return
end tell
答案 1 :(得分:0)
我没有使用keystroke
,而是使用UI Browser找出Messages中内容字段的路径,然后用以下内容替换整个循环:
set value of text area 1 of scroll area 4 ¬
of splitter group 1 of window "Messages" to _msg