设置返回的文本以在applescript中打开应用程序

时间:2014-05-28 19:40:36

标签: ios applescript osx-mavericks

我有一个苹果脚本程序,我正在编程,我想要用户发送的文本来打开一个应用程序,但我不断收到错误消息“无法获取<>的应用程序{”name_of_app“}。代码我很简单,我无法弄清楚问题

set deReturnedItems to (display dialog "How many spam messages?" with icon stop default                         answer "" buttons {"Quit", "OK"} default button 2)
set xpp to text returned of deReturnedItems
set theReturnedItems to (display dialog "How many spam messages?" with icon stop default   answer "" buttons {"Quit", "OK"} default button 2)
set amt to the text returned of theReturnedItems
set daReturnedItems to (display dialog "Last thing, what should the spam message say?"  default answer "" buttons {"Quit", "OK"} default button 2)
set msg to the text returned of daReturnedItems
repeat [amt] times
    tell application [xpp]
        activate
        tell application "System Events"
            keystroke [msg]
            keystroke return
        end tell
    end tell
end repeat

1 个答案:

答案 0 :(得分:0)

摆脱那些方括号。不要将它们用于变量。如果必须,请在之前和之后使用下划线,例如:

repeat _amt_ times
    …
end

此外,在重复块中使用变量之前,需要检查以确保变量是整数。

顺便提一下,当你设置一个变量然后用括号括起来时,那个用于将字符串设置为列表的applescript语法。例如:

set [x, y, z] to "123"
return x
-- returns "1", and y is set to "2", and z is set to "3"