Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Bugfix (A bash script to do the same thing (better?))' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bugfix (A bash script to do the same thing (better?))
Authored by: tpavlic on Jul 11, '07 05:38:21PM
macosxhints.com escaped things that it shouldn't have. Now I'll use a code environment. You should use THIS SCRIPT. Alternatively, just use the script I've linked here.
#!/bin/bash

filename="$1"
lineNum="$2"

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

exec osascript \
 -e "set ESC to ASCII character of 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('$filename')\" & return " \
   -e "keystroke \":exe \\\":buffer \\\" . bufnr('$filename')\"  & return " \
   -e "keystroke \":else \" & return " \
   -e "keystroke \":    edit ${filename// /\\\\ }\" & return " \
   -e "keystroke \":endif\" & return " \
   -e "keystroke \":$lineNum\" & return " \
   -e "keystroke \"zO\" " \
   -e "end tell" \
 -e "end tell"


[ Reply to This | # ]
A few remarks
Authored by: Soliman on Jul 12, '07 03:17:21PM
I modified a bit your script for my setup : since I don't like the error message of z0 if there are no folds under the cursor, I removed that line.

Since I usually run vim in a Terminal with the corresponding title set I had to change the tell application "Vim" to activate into something much more complex:

 exec osascript \
   -e "set ESC to ASCII character of 27" \
   -e "set vimFound to false" \
   -e "tell application \"Terminal\"" \
   -e "   activate" \
   -e "   repeat with theWindow in windows" \
   -e "      if name of the theWindow is \"vim\" then" \
   -e "         set frontmost of theWindow to true" \
   -e "         set vimFound to true" \
   -e "      end if" \
   -e "   end repeat" \
   -e "end tell" \
   -e "if not vimFound then" \
   -e "   tell application \"Finder\" to open POSIX file \"$filename\"" \
   -e "   tell application \"System Events\" to delay 5" \
   -e "end if" \
   -e "tell application \"System Events\"" \
   -e "   tell process \"Vim\"" \
   -e "      if vimFound then" \
   -e "         keystroke ESC & \":set hidden\" & return " \
   -e "         keystroke \":if bufexists('$filename')\" & return " \
   -e "         keystroke \":exe \\\":buffer \\\" . bufnr('$filename')\"  & return " \
   -e "         keystroke \":else \" & return " \
   -e "         keystroke \":    edit ${filename// /\\\\ }\" & return " \
   -e "         keystroke \":endif\" & return " \
   -e "      end if" \
   -e "      keystroke \":$lineNum\" & return " \
   -e "   end tell" \
   -e "end tell"
Just in case somebody else has a setup as weird as I do :)

---
Sylvain

[ Reply to This | # ]