gpt4 book ai didi

python - 在 Automator 服务中将第三方模块与 Python 结合使用

转载 作者:太空宇宙 更新时间:2023-11-04 01:43:45 27 4
gpt4 key购买 nike

我已经在我的机器上安装了 Py-Appscript,它可以与位于 /Library/Frameworks/Python.framework/Versions/Current/bin/python 的 Python 安装一起使用。

我正在尝试将此 Py-Appscript 安装与 Automator 服务结合使用。为此,我使用了 Run Shell Script 操作,然后将 Shell 设置为 usr/bin/python(这是我唯一的选择Python,不幸的是)。

usr/bin/python 似乎无法访问我的第三方模块并在线崩溃:

从 appscript 导入 *

有没有办法让 usr/bin/python 访问我的第三方模块?或者有没有办法告诉 Automator 改用 /Library/Frameworks/Python.framework/Versions/Current/bin/python

我需要 Automator 直接从 Run Shell Script 操作运行 Python。任何调用 Automator 外部的 Python 脚本的操作(例如,通过 bin/bash)的执行速度都不够快,无法发挥作用。

最佳答案

好的,我可以使用在 How do I execute a PHP shell script as an Automator action on Mac OS X 找到的 hack 来让它工作.

运行 Shell 脚本 操作中,我使用了 /bin/sh/外壳与 <<EOF ... EOF到正确的 Python 安装。

例如,输入

/Library/Frameworks/Python.framework/Versions/Current/bin/python <<EOF
from appscript import *
Numbers = app('Numbers')
EOF

进入Run Shell Script 操作的代码部分将起作用。因此可以调用正确的安装(上面的 /Library/Frameworks/Python.framework/Versions/Current/bin/python)并将他们的程序放在 <<EOF 之间。 ... EOF分隔符。

阿尔弗雷德

这个技巧也适用于 Alfred。如果你想使用 appscript和阿尔弗雷德一起,只要确保你通过了{query}到上面的 python 版本,像这样:

/Library/Frameworks/Python.framework/Versions/Current/bin/python script.py {query}

关于python - 在 Automator 服务中将第三方模块与 Python 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2093837/

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