4 Replies Latest reply on Nov 21, 2019 5:33 AM by PascalG

    Can not use VMRUN from Applescript

    PascalG Novice

      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

        • 1. Re: Can not use VMRUN from Applescript
          JessieZhang Enthusiast
          VMware Employees

          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

          • 2. Re: Can not use VMRUN from Applescript
            PascalG Novice

            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?

            • 3. Re: Can not use VMRUN from Applescript
              JessieZhang Enthusiast
              VMware Employees

              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

              • 4. Re: Can not use VMRUN from Applescript
                PascalG Novice

                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