Below are some useful AppleScripts I use on my MacBook Pro. (Download all AppleScripts) One drawback of the Mac is that it sometimes hides functionality in order to simplify the interface. Fortunately, AppleScript can give you back fine grained control.
It really annoys me that there is no keyboard shortcut or menu item for locking the Mac’s screen. You can configure a corner of the screen to enable the screensaver, but you have to hold the mouse in the corner for two seconds are it will turn off the screensaver without prompting you for a password. Therefore, I will sometimes see the screensaver turn on, and I will immediately jump out of my chair causing the mouse to move. This script takes care of that problem.
tell application "ScreenSaverEngine" to activate
DoubleCommand only allows you to save one set of preferences for the user and one set for the entire system. This script will load the User Preferences with button 7 (change the 7 to a 9 for the System Preferences) and activate them with button 6. In the zip archive, this is called my “Windows Keyboard Config” because I swap the command and option keys, since they correspond to the alt and windows keys.
tell application "System Preferences" activate set current pane to pane "DoubleCommand" tell application "System Events" tell application process "System Preferences" tell window "DoubleCommand" click button 7 click button 6 end tell end tell tell application "System Preferences" to quit end tell end tell
MacOS X doesn’t have a separate command for suspending the computer by saving the contents of RAM to disk, like Windows hibernate, but if you change the hibernatemode to “1″ it will suspend to disk whenever you tell it to sleep. Since I want to decide which one to use as opposed to having a static configuration, I have this script which changes the configuration and immediately tells the computer to sleep. I have another script which changes the hibernatemode to “3″ to have the computer sleep normally.
try do shell script "pmset force -a hibernatemode 1" ignoring application responses tell application "System Events" to sleep end ignoring end try

Atom Feed