【问题标题】:Apple Script to turn File Sharing off & on in one scriptApple Script 在一个脚本中关闭和打开文件共享
【发布时间】:2014-08-08 19:22:42
【问题描述】:

我正在竭尽全力编写一个在 10.8 中执行以下操作的脚本。 :

-在“共享”控制面板中取消选中“文件共享”

-检查“共享”控制面板中的“文件共享”

-确保在脚本完成时检查它

我为什么要这样做?因为 10.8 有一个 bug。使用 Samba(无法从另一台机器 smb-login),如果文件共享在启动时被关闭并重新打开,一切都很好。

谁能帮我解决这个问题……?对你们来说应该很容易:-)

非常感谢您,最好的-Ph!L!pp

【问题讨论】:

    标签: macos applescript osx-mountain-lion file-sharing


    【解决方案1】:

    此代码应切换共享首选项,等待 1 秒,然后再次切换。

    tell application "System Preferences"
     activate
    end tell
    
    tell application "System Events"
    tell process "System Preferences"
    click menu item "Sharing" of menu "View" of menu bar 1
    delay 2
    tell window "Sharing"
      click checkbox 1 of row 3 of table 1 of scroll area 1 of group 1
      delay 1
      if (exists sheet 1) then
        if (exists button "Turn AirPort On" of sheet 1) then
          click button "Turn AirPort On" of sheet 1
          delay 1
        end if
        click button "Start" of sheet 1
      end if
    end tell
    end tell
    end tell
    delay 1
    tell application "System Events"
    tell process "System Preferences"
    click menu item "Sharing" of menu "View" of menu bar 1
    delay 2
    tell window "Sharing"
      click checkbox 1 of row 3 of table 1 of scroll area 1 of group 1
      delay 1
      if (exists sheet 1) then
        if (exists button "Turn AirPort On" of sheet 1) then
          click button "Turn AirPort On" of sheet 1
          delay 1
        end if
        click button "Start" of sheet 1
      end if
    end tell
    end tell
    end tell
    

    【讨论】:

    • 谢谢,太快了!但这是否也确保在脚本完成时文件共享处于打开状态......?最好的-
    • 我已经编辑了代码,现在它将切换偏好设置两次。这意味着为了在脚本完成时启用文件共享,您需要在运行脚本之前启用它。
    • 再次感谢!我发现延迟 1 3 (..?) 需要点击来关闭和重新打开……无论如何,让它现在工作。再次感谢并最好-
    • 如果我给你的答案有效,请你点击勾号标记为正确
    • 再次您好,不幸的是它不能可靠地工作……有时在脚本之后共享,有时不是。有任何想法吗 ?最好的-
    猜你喜欢
    • 2013-01-04
    • 2020-09-17
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    相关资源
    最近更新 更多