【问题标题】:Applescript to open Terminal window without sourcing ~/.bash_profileApplescript 打开终端窗口而不使用 ~/.bash_profile
【发布时间】:2013-05-22 03:27:14
【问题描述】:

我正在尝试使用Platypus 为 OSX 10.8 上的交互式命令行程序创建应用启动器。我希望能够双击我的应用程序,并打开一个终端窗口,运行我的程序。问题是我的 Applescript(从 Octave 借来,并适用于 Julia)启动了一个终端窗口并尝试向其中吐出一些命令,但是我有一个相当大的 ~/.bash_profile 干扰了这一点。有没有办法让我的 Applescript 打开非登录 shell,或者不源 ~/.bash_profile 等?

这是 Platypus 运行的脚本:

# This is the startup procedure written as AppleScript to open a
# Terminal.app (if the Terminal.app is not already running) and start
# the Julia program.
# 20071007 removed: open -a /Applications/Utilities/Terminal.app
osascript 2>&1>/dev/null <<EOF
  tell application "System Events" to set ProcessList to get name of every process
  tell application "Terminal"
    activate
    if (ProcessList contains "Terminal") or ((count of every window) is less than 1) then
      tell application "System Events" to tell process "Terminal" to keystroke "n" using command down
    end if
    do script ("exec bash -c \"PATH=${ROOT}/julia/bin:${PATH} OPENBLAS_NUM_THREADS=1 FONTCONFIG_PATH=${ROOT}/julia/etc/fonts GIT_EXEC_PATH=${ROOT}/julia/libexec/git-core GIT_TEMPLATE_DIR=${ROOT}/julia/share/git-core exec '${ROOT}/julia/bin/julia'\"") in front window
  end tell
EOF

# Quit the Julia.application immediately after startup (ie. quitting
# it in the taskbar) because once it is started it cannot be restarted
# a second time. If Julia.app stays (eg. because of a crash) opened
# then restarting is not possible.
osascript 2>&1>/dev/null <<EOF
  tell application "julia"
    quit
  end tell
EOF

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    一般来说,您不需要终端窗口来执行命令行内容。只有当您需要手动输入信息时,您才会使用终端。因此,您可能可以在终端窗口中使用“do shell script”而不是“do script”来运行命令。请注意,这样做不会使用您的 bash 配置文件。所以在applescript中单独尝试这个命令......

    do shell script ("exec bash -c \"PATH=${ROOT}/julia/bin:${PATH} OPENBLAS_NUM_THREADS=1 FONTCONFIG_PATH=${ROOT}/julia/etc/fonts GIT_EXEC_PATH=${ROOT}/julia/libexec/git-core GIT_TEMPLATE_DIR=${ROOT}/julia/share/git-core exec '${ROOT}/julia/bin/julia'\"")
    

    然后您可以根据需要添加其他 applescript 命令,只是不要使用终端,因此您的 bash 配置文件将不会被使用。

    【讨论】:

    • 我的命令行程序是交互式的。事实上,它是一个 REPL,所以在没有终端窗口的情况下运行它是行不通的。
    猜你喜欢
    • 2010-12-20
    • 2018-09-22
    • 2011-12-10
    • 2014-07-20
    • 1970-01-01
    • 2020-08-15
    • 2022-12-11
    • 1970-01-01
    • 2019-02-17
    相关资源
    最近更新 更多