Sample Header Ad - 728x90

How to debug applescript when an Application's class methods don't respond

0 votes
1 answer
237 views
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](https://github.com/macvim-dev/macvim/issues/1266) on MacVim github.
Asked by Polo (141 rep)
Aug 1, 2022, 02:56 AM
Last activity: Dec 11, 2022, 04:04 PM