VMware Communities
derbbre
Enthusiast
Enthusiast
Jump to solution

Fusion Applescript Dictionary and Pausing

VMWare Fusion seems to be rather AppleScript-able, which is great. The dictionary even shows a number of useful commands. I would love to use AppleScript and the AppleScript Menu to allow me to pause/unpuase the current VM. I realize 'pause' is an unsupported feature, but it works for me and it's in the application's dictionary, so I'm going for it.

Anyway - in AppleScript Editor I've created a rather simple script:

tell application "VMware Fusion"

if the paused of the front document then

unpause front document

else

pause front document

end if

end tell

However, whenever I compile, run, or save the script, AppleScript Editor will automagically "correct" my script to:

tell application "VMware Fusion"

if the paused of the front document then

unpause front document

else

unpause front document

end if

end tell

Notice the else clause has changed to unpause... Any ideas how I can prevent AppleScript Editor from doing this? Is this a bug with AppleScript Editor or the app's dictionary?

(Before and After shots enclosed)

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Fixed internally, but as this isn't a supported feature, it wasn't deemed important enough to make the next release.

In the meantime, you can edit the .sdef file to use a different code for unpause (I went with "vxUn!Pau") or use vmrun.

View solution in original post

0 Kudos
16 Replies
derbbre
Enthusiast
Enthusiast
Jump to solution

OK, I found the bug. It is indeed in the application's dictionary

File:

/Applications/VMware\ Fusion.app/Contents/Resources/vmware.sdef

Lines 96-101:

                <command name="pause" code="vxUnPaus" description="Pause a virtual machine">
			<direct-parameter description="The virtual machine to pause." type="specifier"></direct-parameter>
		</command>
		<command name="unpause" code="vxUnPaus" description="Unpause a virtual machine">
			<direct-parameter description="The virtual machine to unpause." type="specifier"></direct-parameter>
		</command>

Looks like both 'pause' and 'unpause' have the same code definition.

I can't for the life of me find where to submit an official bug report. Anyone know?

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

Unless something has changed it is my understanding that VMware Fusion does not natively support AppleScript. Now that's not to say you can't write an AppleScript to interact with Fusion however it's not supported and if you want to script the pause/unpause of a Virtual Machine then use vmrun and you can script that using a shell script.

Have a look at: Using <tt>vmrun</tt> to Control Virtual Machines

0 Kudos
derbbre
Enthusiast
Enthusiast
Jump to solution

Thanks for the reply.

Actually, Fusion does support AppleScript, at least as of 3.1 (the version I'm using.

If you pop open AppleScript Editor and open the Dictionary for VMware Fusion, you'll see a whole slew of commands. (Really, it seems like just an AppleScript port to vmrun, but if you're familiar with AppleScript, it's a great tool.) The bug is in the Fusion dictionary – again, I don't know how to submit an official bug report, but the only issue is with the pause command. All the other power state command work great. You can programmatically manipulate windows as well. (Screenshot included below.)

I'm using a shell script with vmrun for now, but the AppleScript menu sure would be handy.

BTW - love your avatar, been a BSD man for years, wouldn't run a server without it.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Looks like both 'pause' and 'unpause' have the same code definition.

Thanks for tracking this down, I'll take care of it.

I can't for the life of me find where to submit an official bug report. Anyone know?

Unfortunately, our bug tracking system is not public. Developers and support folks try to keep an eye on the forums, but it's best-effort only and things may slip by. Alternately, you could file a support request, which is better tracked but may have to go through some bureaucracy.

admin
Immortal
Immortal
Jump to solution

Fixed internally, but as this isn't a supported feature, it wasn't deemed important enough to make the next release.

In the meantime, you can edit the .sdef file to use a different code for unpause (I went with "vxUn!Pau") or use vmrun.

0 Kudos
Entegy
Hot Shot
Hot Shot
Jump to solution

Can I just say that even in my short time visiting these fourms, I've never seen so much employee support and dedication? Most other places, the best you get are volunteer moderators. And even when they do show up, an employee will say "Feature unsupported, goodbye" But no, here you are still helping. Guess there's a reason VMware's #1. Smiley Happy

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

Actually, Fusion does support AppleScript, at least as of 3.1 (the version I'm using.

I was on a Windows System the other day and couldn't look at the Dictionary in VMware Fusion when I wrote my reply however VMware Fusion when it was first released did not officially support AppleScript even thought a Dictionary, (with next to nothing in it), was present and nowhere in any of the Release Notes for both 2.x and 3.x does it even mention AppleScript much less state it is officially supported. Yes I understand the Dictionary exists and actually has relevant nouns and verbs, etc. etc., however until I see a VMware statement that it's officially supported I'm going to assume it is still a work in progress.

Actually I'm surprised that Eric (etung) didn't comment on my reply as normally he would have at the least to state when things had changed.

I'm using a shell script with vmrun for now, but the AppleScript menu sure would be handy.

I'm glad to see a populated Dictionary now exists for Fusion as it was very disappointing in the beginning and vmrun didn't exist in Fusion 1 either. I like scripting and automation especially since so many tasks can be repetitive it's senseless to constantly do everything manually over and over.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Yes I understand the Dictionary exists and actually has relevant nouns and verbs, etc. etc., however until I see a VMware statement that it's officially supported I'm going to assume it is still a work in progress.

That's correct. AppleScript support is something we'd like to have and are slowly improving, but it's not yet at the point where we're ready to give it an official seal of approval.

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

Thanks Eric... Keep up the good work as Fusion has come a long way from its beginnings. Smiley Happy

0 Kudos
admin
Immortal
Immortal
Jump to solution

Can I just say that even in my short time visiting these fourms, I've never seen so much employee support and dedication?

Thanks for the kind words! Interacting with users directly helps us understand what you guys are interested in and want to do, what things you're having problems with, and so on. We're not going to be able to solve every problem, we're not going to be able to implement every feature -- there just aren't enough hours in the day -- but we are listening and doing our best.

Most other places, the best you get are volunteer moderators.

I'd like to point out that our volunteer moderators and experts are really awesome too :smileysilly: I've certainly learned tips and facts from them.

0 Kudos
Entegy
Hot Shot
Hot Shot
Jump to solution

Oh yeah, I meant no disrepect to them! Really, just cheers all around.

0 Kudos
derbbre
Enthusiast
Enthusiast
Jump to solution

Great, thanks. I had tried to edit the .sdef but forgot each code was supposed to be 8 chars and got a corrupt dictionary error. Went with your suggestion and I'm good. Thanks again.

Looking forward to supported AppleScripting in the future (but using it today, anyway).

0 Kudos
derbbre
Enthusiast
Enthusiast
Jump to solution

Well, thanks to the help here, I've got a handy little AppleScript to drop in the AppleScript Menu that will toggle the paused state for the front-most VM window.

NOTE!!! This script requires the modification listed above and is NOT for the faint of heart. If you don't know how to find files inside of Apps, you probably shouldn't be toying with this. (I shouldn't but did anyway.) Also! Pausing and Unpausing VMs is not supported and probably not a good idea either.

That said:

1) Modify the .sdef file as listed above

2) Turn on your AppleScript Menu

3) Drop

tell application "VMware Fusion"
	if the paused of the front document then
		unpause front document
		display alert "VM Unpaused" message "\"" & the name of the front document & "\" has been unpaused." as informational
	else
		pause front document
		display alert "VM Paused" message "\"" & the name of the front document & "\" has been paused." as informational
	end if
end tell

into ~/Library/Scripts/Applications/VMware\ Fusion

4) Enjoy Pause-y goodness and the CPU power savings!

(My XP VM uses 3.5% CPU on idle but running and only 0.5% paused... that's nice. Get it — nice? I know, not the same.)

Looks like this (not very exciting):

0 Kudos
slehman805
Contributor
Contributor
Jump to solution

VMWare never returns a paused state of "true" though. Maybe i'm missing something.

0 Kudos
WoodyZ
Immortal
Immortal
Jump to solution

VMWare never returns a paused state of "true" though. Maybe i'm missing something.

From the '/Applications/VMware Fusion.app/Contents/Resources/vmware.sdef' file...

<property name="paused" code="Paus" type="boolean" access="r" description="true if the virtual machine is paused">
  <cocoa key="scriptingIsPaused"></cocoa>
</property>

After making an appropriate edit to the erroneous code in the vmware.sdef file and running the AppleScript code presented by derbbre on a running Virtual Machine the following is from the AppleScript Editor's Event Log after running it a second time as the first time returned false an paused the Virtual Machine...

tell application "VMware Fusion"
	get paused of document 1
		--> true
	unpause document 1
end tell

Note that when I referred to "erroneous code" I did not mean in the code for the paused property. I changed the code for the pause command from "vxUnPaus" to "vx__Paus" and left the code for the unpause command as is.

Message was edited by: WoodyZ

0 Kudos
kleinfelter
Contributor
Contributor
Jump to solution

Let me just say that the unsupported Dictionary is infinitely better than no dictionary!

The other major OS X VM has no dictionary, and that is a major factor in my use (and continued purchase of upgrades). Portions of the other major OS X VM are not even gui-scriptable, because the controls aren't "proper" controls. To click them, you have to use absolute screen coordinates and call out to python to send a Quartz event. Ugh!

Thank you for the dictionary.

0 Kudos