0

In Applescript, I'm trying to change which text editor I'm using. TextEdit works fine, providing the document name, and it opens in MacVim. However, when I try the exact same get path of document 1 command in MacVim, it stays undefined, and terminal shows error:

execution error: MacVim got an error: Can’t get document 1. Invalid index. (-1719)

The MacVim library claims it uses the same document object, both really coming from the 'Standard Suite'.

What's my next debug step?

All the Details Below Here

Applescript code to "toggle text editing apps" of the currently open and focused file:

on run argv
    set my_arg to argv
    set the_path to "error - not found"
    
    if (my_arg contains "v") then
        set the_path to from_app("TextEdit")
        open_in_app("MacVim", the_path)
    else if (my_arg contains "e") then
        set the_path to from_app("MacVim")
        open_in_app("TextEdit", the_path)
    else
        display dialog "Error: Use argument 'e' or 'v' to switch TO textEditor or macVim"
    end if
end run

on from_app(from_app)
    tell application from_app
        activate
        set my_path to get path of document 1
        close document 1
    end tell
    
    return my_path
end from_app

on open_in_app(to_app, my_path)
    tell application to_app
        activate
        open my_path
    end tell
end open_in_app

Standard Suite in TextEdit

document n [inh. item; see also TextEdit suite] : A document. elements: contained by application, application. properties: path (text) : The document's path.

TextEdit suite in TextEdit

document n [see also Standard Suite] : A TextEdit document. properties: text (text) : The text of the document.

Standard Suite in MacVim

document n [inh. item] : A document. elements: contained by application. properties: path (text) : The document's path.

Not seeing how to make these images smaller yet...

enter image description here enter image description here enter image description here

How I call the script to get the error

user@userMBP % osascript ~/toggle-text-editor.apple.scpt e

Versions

MacVim was installed with brew install macvim, Custom Version 9.0.65 (173).

Mac is Bug Sur version 11.6.8 (20G730)

Answers to questions

Does homebrew install a gui "MacVim"? Is it launched when the script runs?

Yes, MacVim includes a GUI, and it is successfully launched when the script runs.

What returns from path to application "MacVim"? Is it correct?

Not sure what you mean. open my_path successfully opens the right document in MacVim. set my_path to get path of document 1 fails.

What returns from tell application "Macvim" to documents?

Again, not sure what you mean. There are 2 lines that can issue a tell application MacVim. One is successful (opening document), one fails (asking MacVim the name of currently open document).

Thank you @Mockman and @CJK. Opened issue1226 on MacVim github.

4
  • That error typically implies that there isn't a document 1 available, at least from the script's perspective (including at the time it runs). Does homebrew install a gui "MacVim" as well as cli? Is it launched when the script runs? What returns from path to application "MacVim"? Is it correct? What returns from tell application "Macvim" to documents?
    – Mockman
    Aug 1, 2022 at 7:27
  • @Mockman, I updated post with answers, but I'm not sure what you mean by 2 of them. tell seems to be affecting MacVim correctly, and MacVim is receiving and executing the request to open a document correctly. The call that fails is it does not seem to understand document 1. Do you see any more debug info I can collect?
    – Polo
    Aug 3, 2022 at 9:58
  • You’re not doing anything wrong. MacVim’s scripting hasn’t been implemented properly, so you won’t be able to get it to work.
    – CJK
    Aug 3, 2022 at 16:52
  • @Polo Well, there you have it. Perhaps you could look into emacs.
    – Mockman
    Aug 6, 2022 at 3:11

1 Answer 1

0

The next step was to go to the developer of the Application. In this case, I opened issue1226 on MacVim github.

You must log in to answer this question.

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