【问题标题】:AppleScript access not allowed when trying to run shell script尝试运行 shell 脚本时不允许 AppleScript 访问
【发布时间】:2016-04-09 15:40:02
【问题描述】:

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打开一个新终端

我在得知do script每次都会打开一个新的终端窗口时添加了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? 但是当我运行它时,我得到了同样的错误。

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

【问题讨论】:

    标签: bash shell terminal applescript


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

    【讨论】:

      【解决方案2】:

      这可能只是一个错字

       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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-14
        • 2015-09-10
        • 1970-01-01
        • 2016-11-26
        • 2012-08-08
        • 1970-01-01
        • 1970-01-01
        • 2010-12-12
        相关资源
        最近更新 更多