Reputation: 31523
I'm trying to get this script to run, from the 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"
If I try to run it from the command line:
# Go to line 20 of some_file
$ ./that_script "some_file" 20
I get the following error:
56:64: execution error: File Vim wasn’t found. (-43)
I've tried all sorts:
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
I'm trying to "talk" to a Vim instance running from a Terminal, not a GUI.
Upvotes: 2
Views: 370
Reputation: 196789
Now that you have +clientserver
(from your other question) working, I assume you don't need an answer here anymore but here it is anyway:
AppleScript generally doesn't deal with command line programs.
You can use AppleScript to talk to MacVim (tell application "MacVim" to activate
) but you can't reach CLI Vim at all. AppleScript is for GUI apps only.
Now, most (I hesitate to write "all") Mac OS X GUI applications expose at least a minimal interface for AppleScript called "dictionnary": you can activate the app, get the number of windows, print the active document, open a file… and simulate keystrokes.
The script in your example works — more or less — but only with a GUI Vim. There is a small number of such apps for Mac OS X and this script is designed to work with one called Vim.app. You can change Vim
to MacVim
if you want but you won't be able to make it work with CLI Vim.
Upvotes: 4