1

I have Parallels installed on an M1 Mac. In Parallels, I have a Windows 11 Pro VM. Parallels is configured to share Windows files with MacOS.

This is done via the Network tab in the Finder.

So, to mount the Windows OneDrive in macOS, I need to:

  • Open Finder.
  • Click the Network icon in the sidebar.
  • Click Windows 11.
  • Click [OneDrive] Windows 11.

I have a bash script in macOS that modifies some files on the Windows OneDrive.

When I do the steps above, the Windows OneDrive is mounted at "/Volumes/[OneDrive] Windows 11/imports"

However, if I put the Parallels VM to sleep and then wake it up, I have to manually open Finder and click through the steps to mount OneDrive again.

Is there a way to automatically mount OneDrive in Windows on Parallels (a network drive that is always in the same place) from within a bash script so I can just execute the script instead of manually mounting the drive each time?

Network in Finder

Network in finder

After clicking on Windows 11

after clicking on Windows 11

  • Curios, is the OneDrive folder on the PC the same account/user as on the Mac? If so, why not just access OneDrive directly? – Allan Apr 27 '23 at 16:43
  • @Allan I only have OneDrive installed in Windows, not on the Mac. I'm also editing the files in Windows, so ideally I can do everything in Windows and then just copy the relevant files to the Mac via script. – Patrick Kenny Apr 28 '23 at 01:49

2 Answers2

1

Check for share availability in your script

Instead of manually mounting the share via finder, just do so via script. It will only require two steps:

  1. Check if the share is already mounted
  2. If not mounted, mount it.

This existing post describes mounting a share via command line. We’ll use this information in your script to manually mount the share if it’s not mounted. I’ve created a snippit that checks if the volume exists and is writable then mounts the volume if necessary

   # This should go somewhere below your she-bang and 
   # other CONST/VAR declarations

CONST VAR Declarations

mount_point=“/Volumes/Foo/Bar” server_uri=“//usr:pass@hostname/sharename”

Check if mount point exists and is writable

if ! [[ -w “${mount_point}” && -d “${mount_point}” ]] then mount -t smbfs “${server_uri}” “${mount_point}” else printf “%s already mounted.\n” “${mount_point}” fi

Rest of your code goes here….

In the code…

  • Conditional -w checks if the target is writable
  • Conditional -d checks if the target is a directory
  • Conditional ! preceding the double brackets [[ ]] negates the expression (in other words, if NOT a directory and writable…)
  • Variables are referenced with braces ${} to ensure proper expansion
  • Variables are quoted to handle whitespace characters
Allan
  • 101,432
  • How do I get server_uri for the Parallels share? It shows up as "Windows 11" on the network. I tried //guest@Windows 11 and //guest@Windows \11 but in both cases mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument. – Patrick Kenny Apr 28 '23 at 01:45
  • First, try it manually (not in the script) so you can get working correctly. Second, it appears there’s a space. You could change the “Windows 11” machine name to “Windows_11” or try enclosing it in quotes so your command is mount -t smbfs “//user@windows 11”. You’re escaping the space (my next recommendation ) but you need to do it after the s: …Windows\ 11…. – Allan Apr 28 '23 at 01:50
1

After exchanging several emails with Parallels support, this is the working code I am using in a bash script:

Windows11 is the machine name (I renamed it from the question to remove the space), and then the share to mount as seen on the Network tab in Finder is [OneDrive] Windows11.

function openParallelsNetworkShare {
  open 'smb://guest:@Windows11._smb._tcp.local/[OneDrive] Windows11'
  # Wait for smb to mount the share.
  sleep 4
}