4

I can open a new iTerm window like this:

tell application "iTerm"
    create window with default profile
end tell

How do I do the same but with MacVim?

4

To open a new window in MacVim, you can use the following example AppleScript code:

tell application "MacVim"
    activate
    delay 1
end tell
tell application "System Events"
    keystroke "n" using command down
end tell
  • Note that the value of the delay command may need to be adjusted for your system, and or additional delay commands may or may not be needed. Adjust values of and or add/remove the delay command(s) as appropriate.

Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways to accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

| improve this answer | |
  • 1
    This seems to bring up the existing MacVim window, I was hoping it would create a brand new window instead (same as right click on MacVim icon in the dock and then clicking New Window does). Any ideas on how to achieve this? – zoran119 Apr 23 '18 at 2:05
  • 1
    @zoran119, I've modified the answer. – user3439894 Apr 23 '18 at 2:17
0

From https://gist.github.com/jeetsukumaran/5400816

tell application "System Events"
    set currProcs to (name of processes)
    set MacVimRunning to (currProcs contains "MacVim")
    if not MacVimRunning then
        tell application "MacVim" to activate
    end if
    tell process "MacVim"
        click menu item "New Window" of menu "File" of menu bar 1
        set visible to true
    end tell
end tell
| improve this answer | |
0

This worked better for me. It uses the mvim utility that comes with MacVim to do the hard work. The AppleScript can be simpler and doesn't need special handling if MacVim is already open:

do shell script "cd; {path_to}/mvim &> /dev/null &"
| improve this answer | |
  • Try to explain why it worked and why it was better for you – Nathan Jun 12 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .