2011-07-29 82 views
0

我的Mac连接到我的网络上的SMB共享时出现了一些问题,然后在此之后立即加载应用程序。AppleScript加载卷装入,启动应用程序,并在mac退出挂起时重新启动。

大多数情况下,只需通过设置要在常规登录时挂载的卷开启mac,一切正常,并且还可以在登录时运行应用程序(XBMC)。

有时尽管我没有理由在经过大量故障排除后能够关闭某些卷,但有些时候自动挂载卷会失败,因为它认为网络位置不可用。因此,Mac无法创建卷装,除非我重新启动Mac,然后再次运行。

现在我想要一个AppleScript,它将尝试创建卷装载三(3)次,然后加载XBMC。如果在尝试3次后无法安装音量,请强制Mac重新启动。这会导致脚本在重新启动后再次从头开始运行。

我如何在AppleScript中实现这一点?

问题二:

我有我的Mac订走1小时不活动后暂停。唯一的问题是,如果Mac已经暂停了一段时间,一旦醒来,XBMC无法在一些时间加载远程存储的内容。

因此,当Mac从暂停状态恢复时,是否可以运行脚本,使Mac执行重新启动?

感谢任何读过我的文章的人,我意识到这是一个咆哮。

问候。

回答

0

试试这个为你的第一个问题。至于你的“暂停”问题,我不知道答案。不过,我会考虑launchd。你可以编写一个启动的plist文件,在mac恢复时运行,并且启动的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 
+0

感谢这堆。 还有一件事,当Mac启动时我怎样才能让这个脚本自动运行?那么,当它登录?像平时一样将其设置为登录项目? – Wolferien111

+0

正如原评论员所说,看看launchd。如果你不想和plist混在一起,并从App Store购买Lingon,它会为你处理大部分肮脏的工作。 – Clark

+0

@沃尔菲恩是的。 – fireshadow52

相关问题