【问题标题】:AppleScript to load a volume mount, start an application, and restart if the mac comes out of suspend.AppleScript 加载卷挂载、启动应用程序并在 mac 退出挂起状态时重新启动。
【发布时间】:2011-07-29 02:59:51
【问题描述】:

我的 Mac 连接到网络上的 SMB 共享时遇到一些问题,然后立即加载应用程序。

在大多数情况下,只需像往常一样将音量设置为在登录时挂载,并且在登录时也运行应用程序 (XBMC) 即可打开 mac 时一切正常。

有时,由于我认为网络位置不可用,自动安装卷有时会失败,因为我在进行大量故障排除后无法确定。因此,除非我重新启动 Mac,否则 Mac 无法创建卷挂载,然后它会再次运行。

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

如何在 AppleScript 中实现这一点?

第二个问题:

我将 Mac 设置为在闲置 1 小时后暂停。唯一的问题是,如果 Mac 已经挂起一段时间,在唤醒 XBMC 时,有时无法加载远程存储的内容。

那么,是否可以在 Mac 从暂停状态恢复时运行脚本,从而使 Mac 执行重启?

感谢所有阅读我整个帖子的人,我意识到这有点咆哮。

问候。

【问题讨论】:

    标签: macos applescript restart xbmc


    【解决方案1】:

    第一个问题试试这个。至于您的“暂停”问题,我不知道答案。但是我会调查launchd。您可能可以编写一个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
    

    【讨论】:

    • 非常感谢。还有一件事,我如何让这个脚本在 Mac 启动时自动运行?那么,什么时候登录?像往常一样将其设置为登录项?
    • 如原评论者所说,看看launchd。如果您不想弄乱 plist,请从 App Store 购买 Lingon,它会为您处理大部分脏活。
    猜你喜欢
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多