Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening MacVim from Applescript

I am trying to create a simple Applescript that is activated each time I click a button on the Finder toolbar. This script opens MacVim with the working directory set to the directory that the Finder is at. This is as close as I have got ...

on run
    tell application "Finder" to get folder of the front window as string
    set workingDir to POSIX path of result
    do shell script "cd \"" & workingDir & "\"; /usr/local/bin/mvim"
end run

This works great (mvim automatically sets the working directory of MacVim to the cwd). However for some reason this only works once. It beach balls for a short while and nothing happens If I click the button again. I would have expected to get another blank MacVim window - just as I had typed mvim again in the terminal.

How do I ge the script to do this?

like image 408
Brendan Avatar asked Mar 14 '26 14:03

Brendan


1 Answers

The next calls beachball because the first one is not finished.

To be able to background an applescript process, it must have no dangling output so, change your do shell scriptline to:

do shell script "cd \"" & workingDir & "\"; /usr/local/bin/mvim > /dev/null 2>&1"

it should do the trick.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!