代码之家  ›  专栏  ›  技术社区  ›  Steven Levine

有没有办法通过applescript连接到OSX睡眠/唤醒事件?

  •  2
  • Steven Levine  · 技术社区  · 16 年前

    我想解决的问题很简单。

    当我打开MacBook的盖子时,我喜欢把基座放在屏幕的左侧,但是当我回到家,把MacBook连接到我的电影院显示屏上,并安装双显示器时,我希望基座放在电影院的底部,而不是MacBook的左侧。

    我不想每次连接/断开影院显示器时都进入首选项。

    我有一个50%的问题的解决方案,也就是说,我编写了以下AppleScript代码来根据屏幕分辨率切换Dock的位置,但是我必须手动调用它。

    tell application "Finder" 
    -- Determine Resolution
      set screenSize to bounds of window of desktop
      set screenWidth to item 3 of screenSize
      set screenHeight to item 4 of screenSize
    end tell
    if screenWidth is less than 1900 then    
        --MacBook Display    
        tell application "System Events"      
           tell dock preferences            
                set properties to {magnification:true, screen edge:left}
           end tell
        end tell
    else
        --Cinema Display
        tell application "System Events"
            tell dock preferences
                set properties to {magnification:true, screen edge:bottom}
            end tell
        end tell
    end if
    

    我的问题是:

    • 我是否可以将此代码直接挂接到AppleScript中的OSX睡眠/唤醒事件?有没有什么地方可以“注册”我不知道的操作系统事件上要调用的脚本?

    • 如果不是直接连接,那么还有哪些其他选项可以连接到OSX事件?

    • 你有什么建议吗 改进上述AppleScript代码?

    谢谢。

    1 回复  |  直到 16 年前
        1
  •  4
  •   Josh    16 年前

    尝试通过SleepWatcher执行脚本: http://www.bernhard-baehr.de/