2

我正在尝试从Skim wiki运行此脚本

#!/bin/bash

file="$1"
line="$2"

[ "${file:0:1}" == "/" ] || file="${PWD}/$file"

exec osascript \
  -e "set ESC to ASCII character 27" \
  -e "tell application \"Vim\" to activate" \
  -e "tell application \"System Events\"" \
  -e "  tell process \"Vim\"" \
  -e "    keystroke ESC & \":set hidden\" & return " \
  -e "    keystroke \":if bufexists('$file')\" & return " \
  -e "    keystroke \":exe \\\":buffer \\\" . bufnr('$file')\"  & return " \
  -e "    keystroke \":else \" & return " \
  -e "    keystroke \":    edit ${file// /\\\\ }\" & return " \
  -e "    keystroke \":endif\" & return " \
  -e "    keystroke \":$line\" & return " \
  -e "    keystroke \"zO\" " \
  -e "  end tell" \
  -e "end tell"

如果我尝试从命令行运行它:

# Go to line 20 of some_file
$ ./that_script "some_file" 20

我收到以下错误:

56:64: execution error: File Vim wasn’t found. (-43)

尝试

我尝试了各种方法:

tell application \"vim\" to activate <-- File vim wasn't found
tell application \"/usr/bin/vim\" to activate <-- this raises a 10810 error
tell application \"/path/to/my/own/compiled/vim\" <-- this raises a 10810 error

客观的

我正在尝试与从终端而不是 GUI 运行的 Vim 实例“交谈”。

4

1 回答 1

4

现在你已经+clientserver(从你的另一个问题)工作了,我假设你不再需要这里的答案,但无论如何这里是:

AppleScript 通常不处理命令行程序。

您可以使用 AppleScript 与 MacVim ( tell application "MacVim" to activate) 对话,但您根本无法访问 CLI Vim。AppleScript 仅适用于 GUI 应用程序。

现在,大多数(我不愿写“全部”)Mac OS X GUI 应用程序至少公开了一个名为“字典”的 AppleScript 最小界面:您可以激活应用程序、获取窗口数量、打印活动文档、打开文件…并模拟击键。

您示例中的脚本 - 或多或少 - 但仅适用于 GUI Vim。Mac OS X 有少量此类应用程序,此脚本旨在与名为 Vim.app 的应用程序一起使用。您可以根据需要更改VimMacVim,但无法使其与 CLI Vim 一起使用。

于 2012-04-20T07:21:32.747 回答