如何 运行 Mac 带有在 AppleScript 上编写的参数的应用程序
How to run Mac app with parameters written on AppleScript
有一个简单的脚本和方法。方法接受参数和 return 值。通过脚本编辑器,我确实导出到应用程序并拥有 TestParam.app 文件夹(应用程序)。
问题:如何通过终端 运行 这个应用程序?
目标:传递参数并得到响应
是的,我已经在互联网上进行了一些搜索,但仍然无法运行。我必须为另一个更改签名吗?
on displayError(theErrorMessage)
display dialog theErrorMessage
return "done"
end displayError
您可以使用 osascript
执行处理程序。将应用程序加载为脚本对象和 运行 处理程序
osascript -e 'set scriptAlias to alias "Macintosh HD:Applications:TestParam.app:"' -e 'set theScript to load script scriptAlias' -e 'displayError("Hello") of theScript'
脚本的 运行 处理程序也可以接受(多个)参数,当 运行 通过 [=12] 将其传递时=].例如,在脚本编辑器中输入以下脚本并将其保存在某处:
on run arguments
if (count arguments) is 0 then set arguments to {"no arguments"} -- none passed
repeat with anItem in arguments -- (arguments is a list, even if there is only one)
displayError(anItem)
end repeat
-- the last result will be returned
end run
on displayError(theErrorMessage)
display dialog theErrorMessage
return "done"
end displayError
然后从 终端 ,它可以像任何其他 shell 实用程序一样 运行 通过执行以下操作:
osascript /path/to/your/script 'this is a test' # other arguments as desired
其中 /path/to/your/script
是脚本的实际路径(您也可以将脚本图标拖到 终端 以粘贴其路径)。
有一个简单的脚本和方法。方法接受参数和 return 值。通过脚本编辑器,我确实导出到应用程序并拥有 TestParam.app 文件夹(应用程序)。
问题:如何通过终端 运行 这个应用程序? 目标:传递参数并得到响应
是的,我已经在互联网上进行了一些搜索,但仍然无法运行。我必须为另一个更改签名吗?
on displayError(theErrorMessage)
display dialog theErrorMessage
return "done"
end displayError
您可以使用 osascript
执行处理程序。将应用程序加载为脚本对象和 运行 处理程序
osascript -e 'set scriptAlias to alias "Macintosh HD:Applications:TestParam.app:"' -e 'set theScript to load script scriptAlias' -e 'displayError("Hello") of theScript'
脚本的 运行 处理程序也可以接受(多个)参数,当 运行 通过 [=12] 将其传递时=].例如,在脚本编辑器中输入以下脚本并将其保存在某处:
on run arguments
if (count arguments) is 0 then set arguments to {"no arguments"} -- none passed
repeat with anItem in arguments -- (arguments is a list, even if there is only one)
displayError(anItem)
end repeat
-- the last result will be returned
end run
on displayError(theErrorMessage)
display dialog theErrorMessage
return "done"
end displayError
然后从 终端 ,它可以像任何其他 shell 实用程序一样 运行 通过执行以下操作:
osascript /path/to/your/script 'this is a test' # other arguments as desired
其中 /path/to/your/script
是脚本的实际路径(您也可以将脚本图标拖到 终端 以粘贴其路径)。