Mounting SMB network share on desktop

余生颓废 提交于 2019-12-09 21:08:03

问题


I am trying to mount a smb network share onto the desktop via python, I don't want the share to be mounted in a folder, but were all the other mounted shares are (if I use 'connect to Server' in OSX I want my python mount to be mounted in the same location). Here is the current python code:

directory = os.path.expanduser('~/Desktop')
directory = os.path.normpath(directory)
os.system("mount_smbfs //server/servershare " + directory)

When I run the above, something strange happens. In finder, my home, which has the icon of a house and my username changes to the mount name, it screws it up a bit.


回答1:


If you want to do this this the kosher, Finder-like way, do it in AppleScript via shell via Python:

os.system("osascript -e 'mount volume \"smb://server/servershare\"'")

You don't need anything else -- there's no mount point. This is identical to choosing "Connect To Server", and the resulting volume will show up in /Volumes as expected.

If you need to specify a username and/or password, you can do so:

os.system("osascript -e 'mount volume \"smb://server/servershare\" \
as user name \"myUserName\" with password \"myPassword\"'")

If you want to do it your original way using mount_smbfs, I think you want directory to be a folder you create in /Volumes, e.g. /Volumes/mySmbVolume, though I've never tried to do it this way. As you have it written, you're replacing your actual Desktop folder with the volume you're mounting. You could, however, make a folder inside Desktop for and use that for directory, and it might work. However, I'd do it like I wrote it to be most standard with the usual Mac way of doing things.



来源:https://stackoverflow.com/questions/27598313/mounting-smb-network-share-on-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!