我正在尝试从 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
目标
我正在尝试与从终端运行的 Vim 实例“对话”,而不是 GUI。
最佳答案
既然您已经有了 +clientserver
(来自 your other question ),我假设您不再需要这里的答案,但无论如何:
AppleScript 通常不处理命令行程序。
您可以使用 AppleScript 与 MacVim 对话(告诉应用程序“MacVim”激活
),但您根本无法访问 CLI Vim。 AppleScript 仅适用于 GUI 应用程序。
现在,大多数(我犹豫是否要写“全部”)Mac OS X GUI 应用程序至少公开了一个称为“字典”的 AppleScript 最小接口(interface):您可以激活应用程序、获取窗口数量、打印事件文档、打开文件...并模拟击键。
示例中的脚本或多或少可以工作,但只能与 GUI Vim 一起使用。 Mac OS X 上有少量此类应用程序,此脚本旨在与名为 Vim.app 的应用程序配合使用。如果需要,您可以将 Vim
更改为 MacVim
,但无法使其与 CLI Vim 一起使用。
关于vim - Mac OS X 中看到的 CLI Vim 进程的名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10240757/