English 中文(简体)
Is there a way to hook in to OSX sleep/wake events via Applescript?
原标题:

The problem I am trying to solve is quite simple.

When I open the lid of my MacBook I like to have the Dock on the left side of the screen, but when I get home and connect my MacBook to my Cinema display and set up dual monitors, I want the dock on the bottom of the Cinema, not on the left side of the MacBook.

I don’t want to have to go in to preferences every time I connect/disconnect my Cinema display.

I have a solution for 50% of the problem, namely, I have written the following Applescript code to switch the location of the Dock based upon my screen resolution, but I have to manually invoke it.

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

My questions are:

  • Can I hook this code in to OSX sleep/wake events directly within Applescript? Is there some place where you can "register" scripts to be invoked on OS events that I am not aware of?

  • If not directly, what are some other options for hooking in to OSX events?

  • Do you have any recommendations for improving the above Applescript code?

Thanks.

最佳回答

Try executing your script via Sleepwatcher: http://www.bernhard-baehr.de/

问题回答

暂无回答




相关问题
2 mysql instances in MAC

i recently switched to mac. first and foremost i installed xampp. then for django-python-mysql connectivity, i "somehow" ended up installing a seperate MySQL. now the seperate mysql installation is ...

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

Switching J2SE versions on Mac OS (SnowLeopard)

My current JDK on Mac OS (10.6) is set to 1.6 and I d like to switch to 1.5. A listing of /System/Library/Frameworks/JavaVM.framework/Versions/ shows: lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 ...

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

export to MP3 from quicktime API

A question for Apple,QT programmers. Would like to know if it s possible to export a Movie object to MP3 using the QuickTime API. Preferably the ConvertMovieToFile function. I ve looked at ...

热门标签