3

而不是"asdf",我想在input这里使用变量。

似乎这应该很容易,但由于某种原因我无法弄清楚。

on run {input, parameters}
-- Type 'asdf'
delay 1.900231
set timeoutSeconds to 2.0
set uiScript to "keystroke \"asdf\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
end run

on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
    try
        run script "tell application \"System Events\"
" & uiScript & "
end tell"
    exit repeat
    on error errorMessage
        if ((current date) > endDate) then
            error "Can not " & uiScript
        end if
    end try
end repeat
end doWithTimeout

例如,如果我尝试set uiScript to "keystroke input",我会从 Automator 收到错误:

The action “Run AppleScript” encountered an error.
Check the actionʼs properties and try running the workflow again.
4

1 回答 1

4

我自己想通了。我现在觉得很笨。

set uiScript to "keystroke \"" & input & "\""

于 2013-04-19T20:20:52.187 回答