我的Mac连接到网络上的SMB共享时遇到一些问题,然后在此之后立即加载应用程序。
在大多数情况下,当mac打开时,只要将卷设置为像往常一样在登录时挂载,并且在登录时也运行应用程序(XBMC),一切都可以工作。
但是,在进行了大量的故障排除后,由于没有任何原因,卷的自动挂载有时会失败,因为它认为网络位置不可用。因此,Mac无法创建卷挂载,除非我重新启动Mac,然后它又可以工作了。
现在我想要一个AppleScript,它将尝试创建卷挂载三(3)次,然后加载XBMC。如果尝试3次后仍无法挂载卷,请强制Mac重新启动。这将导致脚本在重新启动后重新开始运行。
如何在AppleScript中实现这一点?
第二个问题:
我把我的Mac设置为在1小时不活动后进入暂停状态。唯一的问题是,如果Mac暂停了一段时间,在唤醒XBMC时,有时无法加载远程存储的内容。
那么,是否有可能在Mac从挂起恢复时运行脚本,使Mac执行重新启动?
感谢所有读过我整篇文章的人,我意识到这有点咆哮。
问候。
第一个问题试试这个。至于你"暂停"的问题,我暂时不知道答案。不过,我会研究一下发射。你可以写一个launchd plist文件,它会在mac恢复时运行,而launchd plist只会使用命令行工具osascript运行applescript。
set remoteDiskName to "Disk Name"
set remoteIPAddress to "192.168.1.xxx"
set user_name to "userName"
set pass_word to "password"
repeat 3 times
set success to mountSMB(remoteDiskName, remoteIPAddress, user_name, pass_word)
if success then exit repeat
delay 1
end repeat
if success then
-- load XBMC
else
tell application "Finder" to restart
end if
on mountSMB(remoteDiskName, remoteIPAddress, user_name, pass_word)
if remoteDiskName is in (do shell script "/bin/ls /Volumes") then
return true
else
set theAddress to quoted form of ("smb://" & user_name & ":" & pass_word & "@" & remoteIPAddress & "/" & remoteDiskName)
set mountpoint to quoted form of ("/Volumes/" & remoteDiskName)
try
do shell script "/bin/mkdir " & mountpoint & "; /sbin/mount_smbfs " & theAddress & space & mountpoint
return true
on error
try
do shell script "/bin/rm -r " & mountpoint
end try
return false
end try
end if
end mountSMB