osascript using bash variable with a space

后端 未结 2 1605
走了就别回头了
走了就别回头了 2020-11-30 07:07

I am using osascript in Bash to display a message in Notification Center (Mac OS X) via Apple Script. I am trying to pass a text variable from Bash to the scrip

2条回答
  •  既然无缘
    2020-11-30 07:34

    This version is completely safe against injection attacks, unlike variants trying to use string concatenation.

    osascript \
      -e "on run(argv)" \
      -e "return display notification item 1 of argv" \
      -e "end" \
      -- "$var2"
    

    ...or, if one preferred to pass code in on stdin rather than argv:

    osascript -- - "$var2" <<'EOF'
      on run(argv)
        return display notification item 1 of argv
      end
    EOF
    

提交回复
热议问题