Parallels Desktop: Suspend/Relaunch VM

Hi together,

So, I tried to make an action that suspends or relaunches a Virtual machine in Parallels Desktop.

According to a Parallels Forum, the terminal command
prlctl suspend "<your_VM>"
works. Turns out it doesn't :roll_eyes:

So I looked into Applescript. No native command to do so according to the Dictionary (would have been too easy…), so UI Scripting is the only way left here.
There is a Parallels Menu Bar Icon in the top right, the "Suspend" option is in the Submenu "Actions". Here the path I found through UI Browser:

But I actually never managed to really Script this part of the Menu Bar :exploding_head: Help from some of our AppleScript experts (@yuuiko? @GoldenChaos? @K2DesignLab?) would be highly appreciated!

Thanks a lot for any help! Stay safe in these times!

tell application "System Events"
	tell process "Parallels Desktop"
		set mBar to menu bar 1
		set mbActions to first menu bar item of mBar whose title is "Actions"
		set mbMenu to first menu of mbActions
		set theSuspendButton to first menu item of mbMenu whose title is "Suspend"
		click theSuspendButton
	end tell
end tell

This should do it. I don't check for anything going wrong here, so you'll probably want to. Also use Apple's Accessibility Inspector to view UI info. At the bottom is the tree that shows all of the elements and their type that you need to follow to get to wherever you're going. You may have to install Xcode for it, I can't remember. You can't UI script without it though.

bettertouchtool has an action built in to do this btw. Just search "menu" when you add something to the trigger.

edit: even another solution is to assign an OS shortcut in the Keyboard preference pane. Shortcuts > App Shortcuts, then add Parallels and follow what it says. You can then trigger with some random combination you'll never use.

Unfortunately this doesn't work :upside_down_face:
menu bar 1 is the app standard bar, isn't it? The utility I need to trigger is in the "utilities" on the top right of the screen.

The idea with the App Shortcut isn't bad btw! used these a lot before BTT. Thanks also for the hint regarding the Accessibility Inspector that I didn't know about!

It works indeed with the keyboard shortcut and the "Send shortcut to specific application" from BTT (the idea is to suspend/wake there VM even it's not frontmost). So if you had an idea on how to access the highlighted item I'd be thankful :slightly_smiling_face:

I’m aware this is an old conversation. But next to this thread there’s very little coming up when googling prlctl "ui scripting". So this seems of interest to a larger audience in my opinion. And there is no answer with a solution yet while I think I have one – or two, actually :slight_smile:.

Solution 1 (faster and more elegant):
You wrote that the terminal command using prlctl didn’t work. I suppose you don’t have the Pro edition of Parallels Desktop and prlctl responds with: “The command is available only in Parallels Desktop for Mac Pro or Business Edition.” I don’t own a Pro or Business license either but am able to use prlctl via a workaround legally*. (Please read my footnote on this – also important for forum moderators.)

Solution 2 (element and item names refer to my German system):
An active VM has its own Dock icon. You can use UI scripting to open its context menu and suspend it, no need for the VM to be frontmost:

tell application "System Events"
	tell process "Dock" to tell list 1 to perform action "AXShowMenu" of UI element "Snow Leopard Server"
	delay 0.5
	click menu item "Aktionen" of menu 1 of UI element "Snow Leopard Server" of list 1 of process "Dock"
	delay 0.5
	click menu item "Standby" of menu 1 of menu item "Aktionen" of menu 1 of UI element "Snow Leopard Server" of list 1 of process "Dock"
end tell

After suspension, the VM’s Dock icon is gone. But for relaunching you can use the context menu of Parallels Desktop’s Dock icon:

tell application "System Events"
	tell process "Dock" to tell list 1 to perform action "AXShowMenu" of UI element "Parallels Desktop"
	delay 0.5
	click menu item "Snow Leopard Server.pvm" of menu 1 of UI element "Parallels Desktop" of list 1 of process "Dock"
end tell

These scripts can be refined by substituting the delays by script snippets that detect whether the respective menus have opened yet.

*According to forum rules “You may not post descriptions of, links to, or methods for stealing someone’s intellectual property …” and I fully understand and subscribe to that. Please note that there is a completely legal way to (partly) use prlctl with a standard license, though. I don’t post the solution here because …
Firstly: Let sleeping dogs lie. That is, though the workaround is in agreement with Parallel’s license, they might otherwise technically prevent it in a future version.
Secondly: The legality depends on the license holder’s situation (I would already tell too much if I would substantiate what I mean with “situation”). That can be checked in a personal message, but not by posting here openly.

Imprint | Privacy Policy