【问题标题】:What is the name of the CLI Vim process as seen by Mac OS X?Mac OS X 看到的 CLI Vim 进程的名称是什么?
【发布时间】:2012-04-20 05:28:56
【问题描述】:

我正在尝试从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 实例“对话”。

【问题讨论】:

    标签: vim applescript


    【解决方案1】:

    既然您已经使用了 +clientserver(来自 your other question),我认为您不再需要这里的答案,但无论如何都在这里:

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

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

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

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

    【讨论】:

    • 谢谢!几个小时前,我刚刚查看了字典,并意识到应用程序必须“半途而废”并提供 Applescript 界面。
    • 嗨@Kit,你有没有想出一个解决方案来让skim back-search与CLI vim/macvim一起工作?我遇到了同样的问题,如果解决了,如果您能分享您的解决方案,我将不胜感激
    猜你喜欢
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 2016-09-21
    • 2012-07-17
    相关资源
    最近更新 更多