如何在Automator中将多个变量作为文本传递/粘贴到Google Chrome中

时间:2019-01-26 06:33:08

标签: applescript automator

创建一个每天运行的cal事件应用程序,要求我自我报告自己的幸福感和压力水平。最终的applescript出现问题,无论尝试如何,我都无法工作。我最接近的是

here's a basic layout of what I'm trying to do

我知道这可能是基本的,所以我非常感谢大家的帮助!

on run {input, parameters}
set hello to item 1 of input as text
tell application "System Events" to keystroke hello
end tell
return input

end run

2 个答案:

答案 0 :(得分:1)

您没有确切说明这些变量中的值将要做什么,但是您可以通过AppleScript操作中的名称来获取工作流变量的值,例如:

value of variable "Happy" of front workflow as text -- or integer, or whatever

请注意,设置变量值操作将输出变量值,在这种情况下,以下要求文本操作将使用该变量值,因此您可以使用忽略输入选项可避免使用以前的结果。这样您的示例工作流程将类似于:

  • 询问文字 {问题:快乐(1-10)}
  • 设置变量的值 {变量: Happy }
  • 询问文本 {问题:受压(1-10)}(忽略输入)
  • 设置变量的值 {变量:强调}
  • 运行AppleScript (请注意,变量在连接到其他文本时会被强制转换为文本):

    on run {input, parameters}
      set happyString to "Level of happiness: " & (value of variable "Happy" of front workflow)
      set stressedString to "Level of stress: " & (value of variable "Stressed" of front workflow)
      display dialog happyString & return & stressedString
    end run
    

答案 1 :(得分:1)

也许此AppleScript代码将为您工作,而不必在Automator工作流程中添加变量

property numberList : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

set happyNumber to (choose from list numberList ¬
    with title "Happiness And Stress Levels" with prompt ¬
    "Choose Your Happiness Level" default items 5 ¬
    OK button name "Continue" cancel button name ¬
    "Cancel" multiple selections allowed false ¬
    without empty selection allowed) as integer

if happyNumber is 0 then return
set happyLevel to "Your Happiness Level Is " & happyNumber

set stressNumber to (choose from list numberList ¬
    with title "Happiness And Stress Levels" with prompt ¬
    "Choose Your Stress Level" default items 5 ¬
    OK button name "Continue" cancel button name ¬
    "Cancel" multiple selections allowed false ¬
    without empty selection allowed) as integer

if stressNumber is 0 then return
set stressLevel to "Your Stress Level Is " & stressNumber

(* Just Un-Comment The Next 2 Lines When You Are Ready To Use Them *)

--tell application "System Events" to keystroke happyLevel
--tell application "System Events" to keystroke stressLevel