Need some Help? Have a tip to share?

Email me at MacTipper@gmail.com, or, leave a comment!

MacTipper Recommends Dropbox!


Dropbox is by far the most useful app I have ever had the pleasure of owning. Best of all, it's free! Check it out here!

4/6/09

Various Macro AppleScripts

A keyboard macro program such as Spark can often use an AppleScript as one of its macros. I've been using Spark for quite a while and here are some of the scripts I use every day:

Black Screen
A SystemUI script to set the brightness of your monitor to 0. While it isn't the fastest script, it does the job.

tell application "System Preferences"
run
set current pane to pane "com.apple.preference.displays"
tell application "System Events"
set value of slider 1 of group 2 of tab group 1 of window "Color LCD" of process "System Preferences" to 0.0
end tell
quit
end tell



Super-Charged "Check for New Mail"

This script will check to see if Mail.app is running. If it isn't, the script launches Mail in the background then checks for new mail. If it is, the script just checks for new mail.

tell application "System Events"
if ((get name of the processes) does not contain "Mail") then
tell application "Mail"
run
end tell
end if
end tell

tell application "Mail"
check for new mail
end tell



Super-Charged Application Launcher
I mainly use this one for iTunes, but it is easily adaptable to some other applications. This script will launch iTunes in the foreground. But, if you run it again and iTunes is the front application, it will hide iTunes.

property app_name : "iTunes"

tell application "System Events"
set front_app to name of (first application process whose frontmost is true)
end tell

if front_app is app_name then
tell application "System Events" to set visible of first application process whose frontmost is true to false
else
tell application app_name to activate
end if



Super-Charged iTunes Play/Pause
This script will play or pause iTunes depending upon whether iTunes is paused or playing. The special part about this script is that if your volume is 0, then the script will raise your volume a little to make sure you hear the music:

tell application "iTunes" to set play_state to player state as string
if play_state is "paused" then

if (output volume of (get volume settings)) is 0 then set volume 2
tell application "iTunes" to play
else
tell application "iTunes" to pause
end if



Volume Management Scripts
I have three scripts related to managing my Mac's volume. The first script sets the volume to the maximum setting:

set volume 10

The second script is a mute script. Unlike traditional mute, this script pauses iTunes if I mute the volume. In addition, it will beep after muting or un-muting the volume. I have my computer set to flash the screen during an alert, so it also gives me visual (and, half the time, aural) notification of the mute status.

set mute_status to (item -1 of ((get volume settings) as list))

if mute_status is false then
set volume with output muted
set mute_status to 1
tell application "System Events"
if (name of every process as string) contains "iTunes" then
tell application "iTunes" to pause
end if
end tell
else if mute_status is true then
set volume without output muted
set mute_status to 0
tell application "System Events"
if (name of every process as string) contains "iTunes" then
tell application "iTunes" to play
end if
end tell
end if

beep


My third volume management script sets the volume output to 0, pauses iTunes, and flashes the screen:

set volume 0
tell application "System Events"
if (name of every process as string) contains "iTunes" then
tell application "iTunes" to pause
end if
end tell

beep



Full Screen Safari Window
This script is pretty much summed up in the title. Make sure you edit the second line so that the last two items in the list (currently 1440 and 900) are the x and y dimensions of your screen. (If you have a MacBook, it is probably 1280 and 800 respectively.)

>tell application "Safari"
set the bounds of the first window to {0, 0, 1440, 900}
end tell



Reload All Tabs in Current Safari Window
Once again, pretty much explained in the title. This script will reload every tab in the frontmost Safari Window:

tell application "Safari"
set this_win to (window 1)
repeat with j from 1 to the count of every tab in this_win
do JavaScript "window.location.reload()" in (tab j of window 1)
end repeat
end tell

3 comments:

  1. Very neat article. I appreciate it. But QuickSilver or Butler offer so much more besides all this.
    ReplyDelete
  2. I've just written an article just like this, but weirdly with none of the same AppleScripts! Quicksilver is my launcher of choice.

    I'll be sure to include a link here when I put it up.
    ReplyDelete
  3. *I mean include a link to here from my article
    ReplyDelete

Note: Only a member of this blog may post a comment.

Subscribe Via Email!

Enter your email address:

Delivered by FeedBurner