gpt4 book ai didi

macos - AppleScript 如何在代码中获取 STDIN?

转载 作者:行者123 更新时间:2023-12-04 21:58:52 25 4
gpt4 key购买 nike

谷歌建议

echo "input" | osascript filename.scpt

filename.scpt
set stdin to do shell script "cat"
display dialog stdin

但是,我只能得到空白对话框:它没有文本。如何从 AppleScript 的版本中获取标准输入?

我的操作系统版本是 OSX 10.8 Mountain Lion。

最佳答案

根据 this thread ,从 10.8 AppleScript 开始积极地关闭标准输入。通过将它滑出一个未使用的文件描述符,它可以被保存。这是在 bash 中执行此操作的示例。

在这里,我们再次使用 cat从魔法中读取子进程 fd .

$ echo world | osascript 3<&0 <<'APPLESCRIPT'
> on run argv
> set stdin to do shell script "cat 0<&3"
> return "hello, " & stdin
> end run
> APPLESCRIPT
hello, world
$

关于macos - AppleScript 如何在代码中获取 STDIN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13973347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com