Applescript,通过击键输入的文本无法格式化

时间:2016-12-22 18:16:26

标签: text applescript

您好我正在使用Applescript在Safari网页上输入文字。

其中一个字段是一个电话号码,当用户(人类)输入数字时,该电话号码将用括号格式化。

例如,如果用户输入

  

123456789

该字段最终看起来像这样

  

(12)3456789

出于某种原因,当我的脚本“输入”相同的数字时,它们不会被格式化,即使它们完全相同。

脚本非常简单

if Celular is not "" then
    keystroke Celular
    delay tiempo
end if

任何我可以做错的提示?

非常感谢提前

1 个答案:

答案 0 :(得分:0)

首先,使用密钥代码选择两个选项。

tell application "System Events" 
if Celular is not "" then
    keystroke Celular
    delay tiempo
    key code 48 -- a tab
end if
end

或者,您可以先尝试自己格式化数字:

set Celular to "5558675309"
set Celular to "(" & (text 1 thru 3 of Celular) & ") " & (text 4 thru 6 of Celular) & "-" & (text 7 thru 10 of Celular)