0

Using MacOS Mojave, I recently intalled the last version of vim thanks to this easy tutorial : https://medium.com/swlh/vim-is-vulnerable-update-vim-on-macos-66402e5ab46a

I am now trying to synchronize it with Skim to do backward search. To do so, I am using a script in which vim is activated using AppleScript with the following command :

osascript -e 'tell app "Vim" to activate'

I get the following error when executing:

18:26: execution error: Il est impossible d’obtenir application "Vim". (-1728)

(translation from French : It is impossible to obtain application "vim")

macerror -1728 gives me:

Mac OS error -1728 (errAENoSuchObject): e.g.,: specifier asked for the 3rd, but there are only 2. Basically, this indicates a run-time resolution error.

I have tried changing "vim" to "Vim" in the command; creating a symlink from vim in /Applications to vim in /usr/local/bin ; changing owner of vim to $USER. Nothing worked.

Anyone has any idea what is going on ?

FlatKos
  • 17
  • 1
  • 6

2 Answers2

1

AppleScript is unfortunately only for GUI apps - therefore you won't be able to manage CLI Vim at all. I can see that any other solutions won't make you happy, since the tutorial is about using particular vulnerability. You can make

brew install macvim

to operate on the functionalities that vim provides, so you can still record keystrokes, print stuff and so on. You can also read about vim +clientserver, it might provide a solution for your needs, but it'd be still just a workaround.

Radoslaw Dubiel
  • 122
  • 2
  • 9
  • Thanks for this clear and simple answer. That's what I feared, but that is not that important in the end. Might install macvim in the future. – FlatKos Sep 10 '20 at 16:53
  • @user3439894 below provided another solution that helped me a bit, allowing me to build an not-so-perfect script to do backward search with vim. The main problem is that AppleScript is not suitable to manage CLI apps and I cannot properly check if my GLI vim is running. I will probably try with shell scripting. – FlatKos Sep 11 '20 at 10:10
1

Since vim in this use case is a command line executable, not a standard GUI app, the following example AppleScript code should work:

osascript -e 'tell app "Terminal"' -e 'do script "/usr/local/bin/vim"' -e 'activate' -e 'end tell'

Note: If necessary, change the fully qualified pathname of vim to where you installed it.

user3439894
  • 7,266
  • 3
  • 17
  • 28
  • Didn't work for me, but this did: `osascript -e 'tell app "Terminal" to do script "vim"'` – brennanyoung Sep 11 '20 at 08:49
  • (although... if we're already in the shell, why are we going via osascript?) – brennanyoung Sep 11 '20 at 08:50
  • Thanks @user3439894 this is helping. I managed to somehow build a pdf-synchronization script between skim and CLI vim, but it is not perfect since AppleScript is not suitable to manage CLI apps and cannot check if my GLI vim is already running. – FlatKos Sep 11 '20 at 10:11
  • 1
    @brennanyoung I'm a beginner. I just took this script from the vim website and tried to understand and adapt it at the same time: https://www.vim.org/scripts/script.php?script_id=1951. But I am going to try to make another one in shell script, this should be more suitable. – FlatKos Sep 11 '20 at 10:11
  • 1
    @brennanyoung, RE: "Didn't work for me" -- In the link of the OP `vim` was installed to `/usr/local/bin/`, so as not to overwrite the **macOS** _default_ `vim`. I added a _note_ to change the _fully qualified pathname_ of `vim` to where one installed it. That said, I have no idea why the OP is wanting to open `vim` in this manner, my only interest was providing workable **AppleScript** _code_ based on what the OP presented. – user3439894 Sep 11 '20 at 18:45