How to minimize VS Code

From my understanding, this does not work because VS Code does not have a dictionary

tell application "System Events" to tell process "Code"
	tell window 1
		set miniaturized to true
	end tell 
end tell

So then the only option is to use a keystroke, correct?

Someting like:

tell application "System Events" to keystroke "m" using {command down}

I can’t get VS Code to activate in the first place though.

-- none of these work
tell application "Electron" to activate
tell application "Visual Studio Code" to activate
tell application "System Events" to tell application process "Code" to activate

tell application "System Events" to set code to (first application process where short name = "Code")
tell code to activate

Part of the problem is that I don’t understand the difference between an application and an application process.

Does anyone have any suggestions? Thanks!

How about this?

tell application "System Events"
	tell process "Code"
		set visible to false
	end tell
end tell

The app name is “Visual Studio Code”.
The process name is “Electron”.
And as you noticed, miniaturized is buggy.

This should do the job:

tell application "Visual Studio Code" to activate

tell application "System Events" to tell application process "Electron"
	tell (window 1 whose value of attribute "AXSubRole" = "AXStandardWindow") -- make sure we work with a document window
		set value of attribute "AXMinimized" of it to true 
	end tell
end tell

Both these solutions work, thanks! For anyone else, @Piyomaru 's solution hides the window as opposed to minimizing it. @ionah I couldn’t get the activate line to work, but it isn’t needed. The second part minimizes VS Code regardless of whether it’s in the foreground.

It’s not buggy. It’s just not a property of window class objects that are subclasses of UI element. miniaturized is defined strictly for the top-level window class objects that belong to and are immediate children of an application class object. While System Events does have such a class defined, it’s only by virtue of it being part of the standard suite that I think any scriptable application has in its scripting definition file regardless of whether it will implement all (or any) of the commands and classes within. System Events is strictly a background application, so naturally doesn’t ever have any windows of its own.