尝试 运行 shell 脚本时不允许访问 AppleScript

AppleScript access not allowed when trying to run shell script

AppleScript 的新手,但我正在尝试从终端脚本迁移过来。经过大量研究,我在尝试从 .app 文件中获取 shell 脚本 运行ning 时遇到问题。

我目前拥有的:

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

得知do script每次都打开一个新终端window时加了in window 1,参考: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? 但是当我 运行 它时,我得到了同样的错误。

那么如何才能 运行 shell 位于同一 window 1 文件夹内的 Scripts 脚本?理想情况下,我想为路径设置一个变量,这样我就可以将多个 shells 脚本放在 Scripts 文件夹中。

可能是打错了

 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

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 脚本,这种方法会有所帮助。