我使用以下脚本https://github.com/chilcote/warranty
它与终端配合得很好。
现在我想将它与 applescript 一起使用。
我想到“执行 shell 脚本”,并且该脚本位于“Resources”目录中
我尝试这解决方案,但是没有作用。
我的目标:我想要一个可以显示保修状态的苹果脚本应用程序。
感谢您的帮助。
我的 applescript 代码
set warranty to do shell script "bash " & POSIX path of (path to me) & "Contents/Resources/warranty.sh"
display dialog warranty
错误:
error "/Users/tz/Desktop/warranty: line 43:
Apple warranty estimation script.
This script estimates whether a given serial number is under warranty.
Input can be one or more given serial numbers, or a text file listing serials.
Output can be standard out or a CSV file.
usage: warranty [-h] [-v] [--quit-on-error] [-i INPUT] [-o OUTPUT] ...
positional arguments:
serials
optional arguments:
-h, --help show this help message and exit
-v, --verbose print output to console while writing to file
--quit-on-error if an error is encountered
-i INPUT, --input INPUT
import serials from a file
-o OUTPUT, --output OUTPUT
save output to a csv file
: command not found
/Users/tz/Desktop/warranty: line 45: import: command not found
/Users/tz/Desktop/warranty: line 46: import: command not found
/Users/tz/Desktop/warranty: line 47: import: command not found
/Users/tz/Desktop/warranty: line 48: import: command not found
from: can't read /var/mail/dateutil
/Users/tz/Desktop/warranty: line 50: import: command not found
/Users/tz/Desktop/warranty: line 51: import: command not found
/Users/tz/Desktop/warranty: line 52: import: command not found
/Users/tz/Desktop/warranty: line 53: import: command not found
/Users/tz/Desktop/warranty: line 54: import: command not found
/Users/tz/Desktop/warranty: line 56: syntax error near unexpected token `('
/Users/tz/Desktop/warranty: line 56: `def get_asd_plist():'" number 2
答案1
从评论中复制:
该
warranty
脚本是 Python (.py
) 脚本,而不是 Bash (.sh
) 脚本。错误来自 bash,因为您的 AppleScript 强制在 下运行保修bash
。
换句话说,你想要
set warranty to do shell script "python " & POSIX path of (path to me) & "Contents/Resources/warranty.sh"
(或者"python3 "
如果脚本是 Python 3 脚本并且您参考的python
是 Python 版本 2)。
这是从错误消息中推断出来的;也许该脚本是用另一种语言编写的。import
和from
是 Python 脚本中的常用关键字,因此这个推断可能是一个很好的猜测;但如果不看脚本源代码的开头,我们就无法确定warranty
。