VMware Communities
PascalG
Contributor
Contributor
Jump to solution

Can not use VMRUN from Applescript

Hello,

I managed to execute "start" and "stop" vmrun commands if i use Terminal, but I use the same commands in Applescript I get the error "Cannot open VM: /Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx, Cannot read the virtual machine configuration file."

remark: the proper name of the folder is "Virtal Machine", with the spelling mistake 😞

Commands I use with Terminal: and both work!

vmrun stop /Users/pascal/Documents/Virtal\ Machine/Win\ 10\ x64\ iMac\ 2017.vmwarevm/Win\ 10\ x64.vmx soft

vmrun start /Users/pascal/Documents/Virtal\ Machine/Win\ 10\ x64\ iMac\ 2017.vmwarevm/Win\ 10\ x64.vmx

The syntax I use in Applescript:

property usr : "myuser"

property pswd : "mypsw"

do shell script "sudo /Applications/'VMware Fusion.app'/Contents/Library/vmrun start '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx'" user name usr password pswd with administrator privileges

do shell script "sudo '/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft" user name usr password pswd with administrator privileges

Can you tell me what i do wrong in applescript?

Manhy thanks

mac book air Catalina

Fusion 11.5.1

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
PascalG
Contributor
Contributor
Jump to solution

JessieZhang,

I found the problem, in fact I didn't put the double quote at the right position... Sorry it was a silly mistake!

I wrongly wrote:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft" user name "my user" password "my psw" with administrator privileges

but I should wrote:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft user name 'my user' password 'my psw' with administrator privileges"

I moved the double quote from after soft to after privileges.

However I noticed that I do not need the privileges stuff, so my final command is:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft"

Et voilà,

Thank you for your help

View solution in original post

Reply
0 Kudos
4 Replies
JessieZhang
VMware Employee
VMware Employee
Jump to solution

PascalG​,

Do not use 'sudo' in AppleScript, the permission can be escalated by using the following patthern:

    do shell script "command" user name "username" password "pass" with administrator privileges

You can experiment by running the following lines in Apple Script:

1) do shell script "cat /etc/sudoers"
2) do shell script "cat /etc/sudoers" user name "username" password "pass" with administrator privileges

My test with using vmrun in AppleScript works:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' start '/Volumes/10.14/Users/Shared/Windows 10.vmwarevm/Windows 10 x64.vmx'" user name "username" password "pass" with administrator privileges

Reply
0 Kudos
PascalG
Contributor
Contributor
Jump to solution

Hi JessieZhang,

Thank you for your answer, as I am a complete beginner with Applescript and vmrun!

I removed the sudo and I get the same error message... I tried your cat command and it works fine with the user/psw attributes.

This is my command now:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft" user name "my user" password "my psw" with administrator privileges

Screenshot 2019-11-20 at 10.41.13.png

I have the same error with vmrun start, but I noticed in the Result window a number (255?) at the end of the error message:

error "Error: Cannot open VM: /Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx, Cannot read the virtual machine configuration file" number 255

Any idea what it can be?

Reply
0 Kudos
JessieZhang
VMware Employee
VMware Employee
Jump to solution

Pascal​,

That seems to be a permission issue. Could you please provide more information?

1) What happens if you launch Fusion, then start up and shut down the same VM? Does the same error message show up?

2) Open a Terminal window, run below command to see if there is any permission issue with the vmx file

    ls -all /Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm

Reply
0 Kudos
PascalG
Contributor
Contributor
Jump to solution

JessieZhang,

I found the problem, in fact I didn't put the double quote at the right position... Sorry it was a silly mistake!

I wrongly wrote:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft" user name "my user" password "my psw" with administrator privileges

but I should wrote:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft user name 'my user' password 'my psw' with administrator privileges"

I moved the double quote from after soft to after privileges.

However I noticed that I do not need the privileges stuff, so my final command is:

do shell script "'/Applications/VMware Fusion.app/Contents/Library/vmrun' stop '/Users/pascal/Documents/Virtal Machine/Win 10 x64 iMac 2017.vmwarevm/Win 10 x64.vmx' soft"

Et voilà,

Thank you for your help

Reply
0 Kudos