这是一个
实例
如何在
行动
自动机服务
:
on run {input, parameters}
tell application "System Events"
-- # Get the name of the App that has focus when this Service is triggered.
set activeApp to name of first application process whose frontmost is true
delay 0.5
end tell
tell current application
activate -- # Set focus back to me so the list box is frontmost.
set contactName to (choose from list {"John", "Bob", "Jill"} with prompt "Who do you want to contact?") as string
if return is false then return -- # User clicked Cancel or pressed Esc, exit the run handler.
if contactName is "John" then
set phoneNumber to "(310) 213-1234"
else if contactName is "Bob" then
set phoneNumber to "(213) 123-1234"
else if contactName is "Jill" then
set phoneNumber to "(424) 456-7890"
end if
set the clipboard to "Hi, please contact " & contactName & " at: " & phoneNumber & linefeed & "Thank you."
end tell
-- # Set focus back to the App that was frontmost when the Service was triggered.
tell application activeApp
activate
delay 1 -- # Make sure the App has come frontmost before pasting what's on the clipboard.
tell application "System Events"
try
-- # Insure the front window is indeed active.
perform action "AXRaise" of window 1 of application process activeApp
delay 0.2
end try
try
-- # Paste from the clipboard.
keystroke "v" using command down
delay 0.2
end try
end tell
end tell
-- # Clear the clipboard.
tell current application to set the clipboard to ""
end run
注:
这个
delay
可能需要也可能不需要和/或其
可能需要根据您的系统进行调整。你总是可以删除那些你发现你不需要的,但我觉得他们的战略位置,并将留在他们。