AppleScript新手,但我尝试从终端脚本迁移。经过大量研究后,我遇到了尝试从.app文件中运行shell脚本的问题。
到目前为止我所拥有的:
to the_foo()
tell application "Finder"
set current_path to container of (path to me) as alias
set path_in_posix to POSIX path of current_path
end tell
tell application "Terminal"
set new_terminal to do script " "
activate
do script "cd " & path_in_posix in window 1
do shell script "ls " & POSIX path of (path to me) & "Contents/Resources/Scripts/foobar.sh" in window 1
end tell
end the_foo
我得到的错误:
学会用Applescript to open a NEW terminal window in current space
打开一个新终端当我得知in window 1
每次都打开一个新的终端窗口时,我添加了do script
,引用:applescript and terminal ( run several do shell script in one terminal window )
我最初尝试过:
set script_Location to path to resource "Contents:Resources:Scripts:"
set run_Script to (quoted form of script_Location) & "foobar.sh"
do shell script run_Script
引用后:How to change AppleScript path to a Terminal-style path?但是当我运行它时,我得到了同样的错误。
那么如何在同一Scripts
内的window 1
文件夹中运行shell脚本?理想情况下,我想为路径设置一个变量,这样我就可以在Scripts
文件夹中放置多个shell脚本。
答案 0 :(得分:1)
这可能只是一个错字
do script "ls " & POSIX path of (path to me) & "Contents/Resources/Scripts/foobar.sh" in window 1
而不是
do shell script "ls " & ...
我建议使用System Events
代替Finder
来获取脚本的容器
tell application "System Events"
set path_in_posix to POSIX path of container of (path to me)
end tell
答案 1 :(得分:1)
Vadian在一个班轮上有正确和更好的方法。我确实改变了
"Contents/Resources/Scripts/foobar.sh"
到
set script_Location to "Contents/Resources/Scripts/"
set foobar to do script "bash " & POSIX path of (path to me) & script_Location & "foobar.sh" in window 1
如果我想在Scripts
文件夹中添加多个shell脚本,这种方法会有所帮助。