给定:脚本中包含多个功能(见下文)
Wanted :从命令行按名称调用函数,例如osascript lib.scpt fn1
问题:执行上面的命令会出现“lib.scpt:execution error:«script»不理解argv消息。( - 1708)”
如何按名称调用函数?
on run argv
argv() // <-- here's the problem
end run
on fn0()
return "hello from fn0"
end fn0
on fn1()
return "hello from fn1"
end fn1
答案 0 :(得分:0)
我想我找到了你要找的东西on MacScripter:
on run argv
set arg to (item 1 of argv)
set scpt to "on run inArgs\n(item 1 of inArgs)'s " & arg & "()\n\tend"
run script scpt with parameters {me}
end run
on fn0()
return "hello from fn0"
end fn0
on fn1()
return "hello from fn1"
end fn1