Approach 1 - Configure your Mac to automatically mount an SMB share at Login
Approach 2 - Connect via VPN
tell application "Viscosity"
set connectionState to "dunno"
repeat until (connectionState = "Connected")
if connectionState = "Disconnected" then
connect "VPN_CONNECTION1"
connect "VPN_CONNECTION2"
end if
set connectionState to state of connections where name is equal to "VPN_CONNECTION1"
set connectionState to connectionState as string
end repeat
tell application "Finder"
activate
if (count of windows) is 0 then
mount volume "smb://username:password@IP_address/share"
mount volume "smb://username:password@IP_address/share"
end if
end tell
end tell
The above apple script will automatically startup my Viscosity VPN and upon a succesfull connection it will start to connect to my SMB servers. If you export the code to an application and then put it into your login items it will automatically connect everytime you startup.
Approach 3 - Auto Connect Without Popup
-
打开 Automator
-
创建一个“应用程序”
-
点击“Run AppleScript”这个action,拖动到右侧面板
-
输入待运行命令,比如
do shell script "sudo whatevercommandyouwanttorun" with administrator privileges # run a apple script osascript /Users/shiwei/SW/auto_smb_connect.scpt
-
保存这个“应用程序”
-
尝试打开这个应用程序,测试他的可用性
-
在系统偏好设置——用户与群组——登录项中,添加刚保存的application
Reference
- https://apple.stackexchange.com/questions/306739/connect-to-smb-server-on-startup
- https://www.csd.uwo.ca/~amulder/HowTo/smb-mounts-login/
- https://superuser.com/questions/336665/how-to-automount-smb-shared-network-drives-in-mac-os-x-lion
- https://www.jianshu.com/p/60af47061cc1
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper