【问题标题】:hide menu bar and dock globally with applescript使用applescript全局隐藏菜单栏和停靠
【发布时间】:2013-01-04 05:02:58
【问题描述】:

我正在尝试让 OS X Lion 中的停靠栏和菜单栏在全局范围内自动隐藏。我希望它对所有程序都这样做的原因是因为我正在尝试在 wine 中玩游戏,并且在全屏运行时 CPU 使用率会飙升,所以在玩窗口时我总是不得不手动告诉在播放前停靠以隐藏。

我知道编辑 info.plist 和 LSUIPresentationMode 键,但不幸的是,游戏启动器注意到该文件已被编辑并在启动前修复它。所以我唯一的选择是在开始之前将它隐藏在所有程序中,这可能吗? AppleScript 甚至是解决此问题的最佳方法吗?我对在 Mac 上进行编码还是很陌生,因此对于如何完成此操作的任何建议都表示赞赏。

【问题讨论】:

    标签: macos osx-lion applescript


    【解决方案1】:

    对于大苏尔:

    tell application "System Events"
        tell dock preferences to set autohide menu bar to not autohide menu bar
    end tell
    

    【讨论】:

    • 我没想到会这么简单,但它确实有效。我想这至少有 1 个理由升级到 Big Sur。
    【解决方案2】:

    对于那些仍然感兴趣的人,这对于那些使用 OS X 的人来说是一个解决方案。“常规设置”页面现在从 tab 不起作用的搜索栏开始。这是一个解决方法。

    tell application "System Preferences"
    
        --open General Settings
        activate
        set the current pane to pane id "com.apple.preference.general"
        try
    
            --wait for screen to boot
            repeat until window "General" exists
                delay 0.2
            end repeat
            delay 0.5
        on error error_message
            get error_message
        end try
    end tell
    
    
    --click the appropriate check box
    tell application "System Events"
        click checkbox "Automatically hide and show the menu bar" of window "General" of application process "System Preferences" of application "System Events"
    end tell
    

    【讨论】:

      【解决方案3】:

      这是一个为我做的苹果脚本,因为它也是我真正想看到的东西。我不确定它是否会赢得风格点数,但我使用 Automator 服务调用它并为其设置键盘快捷键,此后我再也没有抱怨过。

      tell application "System Events"
          tell dock preferences
              --get the properties list of the dock and set (or assign) it to our variable we'll call "dockprops"
              set dockprops to get properties
              --in our now "dockprops" list, assign our target dock property ("autohide") to the variable "dockhidestate"
              set dockhidestate to autohide of dockprops
              --the dock's "autohide" property is a boolean: it's value can only be either true or false
              --an "if statement" provides the necessary logic to correctly handle either of these cases in this one single script
              if autohide = true then
                  tell application "System Events"
                      tell dock preferences to set autohide to not autohide
                  end tell
              else
                  set autohide to true
              end if
          end tell
      end tell
      
      tell application "System Preferences"
      
          activate
          --  tell application "Finder" to tell process "System Preferences" to set visible to false
          set the current pane to pane id "com.apple.preference.general"
      
          --  The delays are necessary as far as I can tell
          delay 0.5
          tell application "System Events" to keystroke tab
          delay 0.5
          tell application "System Events" to keystroke tab
          tell application "System Events" to keystroke tab
          tell application "System Events" to keystroke space
          tell application "System Events" to key code 13 using {command down}
      end tell
      

      【讨论】:

        【解决方案4】:

        您可以轻松完成停靠。我不知道如何全局做菜单栏。我怀疑这是可能的。这是码头的脚本。它将根据当前情况将其切换为自动隐藏或不自动隐藏。祝你好运。

        tell application "System Events"
            tell dock preferences to set autohide to not autohide
        end tell
        

        【讨论】:

        • 太好了,谢谢。我在 Google 上找到的东西肯定已经过时了,正如我所说的,我已经编码了很长时间,但对 AppleScript 一无所知,AppleScript 非常陌生,当然也不是基于我以前使用过的任何东西。
        • 很高兴为您提供帮助。 Applescript 很简单。就像其他语言一样,它有 if 语句、重复循环和其他正常的东西。它的用途是控制其他应用程序。所以基本上,如果你有一个想要控制的应用程序,你可以通过检查它是否有一个 applescript 术语词典来查看应用程序是否接受 applescript 命令。如果是,你可以控制它。您可以使用“选择词典”在 AppleScript 编辑器的文件菜单下检查词典。你在那里寻找你的应用程序,如果你找到它,你可以通过它查看你可以向它发出的命令。很简单。
        • 虽然这曾经是一个很好的解决方案,但在 Mojave 中,它的 AppleEvent Sandboxing 要求用户允许将 AppleEvents 发送到“系统事件”,该脚本第一次运行时,这个解决方案不如以前好。 @ regulus6633,有没有办法绕过AppleEvents?我担心用户会“禁止”AppleEvents,然后会发生错误。可能是 UserDefaults 或 CFPreferences?
        猜你喜欢
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多