EventScripts Icon

Example Scripts

AppleScript Examples

You can download an archive of example scripts for EventScripts and EventScripts Mobile. The examples include template scripts for every event, and show how to use the arguments passed by EventScripts when the script is executed. It also includes a small selection of scripts that you might like to try with EventScripts Mobile.

Walkthrough examples

I like the app Flutter a lot, it lets you play and pause iTunes with hand gestures. However I don't like it turning my camera on even when I am not using iTunes.

The example below solves this by launching and quitting Flutter as iTunes is launched and quit.

Just hook up the script below both the "iTunes will launch" and "iTunes will quit" events with EventScripts.

The scripts uses the parameters passed by EventScripts to work out whether it should quit or launch Flutter.

-- This script launches and quits Flutter as iTunes is launched and quit

-- means my iSight camera is not on all the time :-)

on run eventArgs

set thisTrigger to (trigger of eventArgs)

if thisTrigger is "iTunes will launch" then

-- We want to launch the utility Flutter

-- when the application iTunes launches

tell application "Flutter"

activate

end tell

else if thisTrigger is "iTunes quit" then

-- We want to quit the utility Flutter

-- when the application iTunes quits

tell application "Flutter"

quit

end tell

end if

end run

When EventScripts triggers an AppleScript it passes the record containing information about the event. This example uses some of parameters passed by EventScripts when a script is triggered by the "iTunes track changed" event.

-- This script changes the status of iChat when to the current track

-- playing in iTunes, using values passed by EventSripts

on run eventArgs

-- Let's check we're being triggered by the correct event

if (trigger of eventArgs is "iTunes track changed") then

-- Not very original :-)

tell application "iChat"

set status message to "Listening to: " & (track of eventArgs as string) & " by " & (artist of eventArgs as string)

end tell

end if

end run

Here's another example that uses the parameters passed on the "Volume unmounted" event to check what volume has been unmounted, and remounts the volume as necessary.

-- This script changes remounts a server volume

-- when EventScripts tells us it has been unmounted

on run eventArgs

-- Let's check we're being triggered by the correct event

if (trigger of eventArgs is "Volume unmounted") then

-- Let's find out what volume name has been unmounted

if (volumeName of eventArgs is "myshare") then

-- Let's remount the server

tell application "Finder" to mount volume "afp://mac-mini.local/myshare"

end if

end if

end run

Here's a final AppleScript example which checks how far we are from home (using Location Helper). If we're more than 100km from home, it displays a dialog.

-- This script uses Location Helper and will 

-- display a dialog when we're more than 100kms from 'home'

property myHome : {51.5, -0.1167}

on run eventArgs

if (trigger of eventArgs) is "Location updated" then

tell application "Location Helper"

set distanceFromHome to get distance from coordinates myHome

end tell

if distanceFromHome > 100000 then

-- We're more than 100km from home

display dialog "Where are we going?!"

end if

end if

end run

Shell Script Examples

When EventScripts triggers a shell script it sets environment variables to pass parameters. The example below show a shell script that, when attached to the "Screenshot taken" event, uploads screenshots to an ftp server as you take them.

#!/bin/sh

if [ "$1" == "Screenshot taken" ]; then

HOST='upload.example.com'

USER='yourname'

PASSWD='yourpass'

ftp -n $HOST <<END_SCRIPT

quote USER $USER

quote PASS $PASSWD

put "$3" "$2"

quit

END_SCRIPT

fi

Check out the table of events and parameters.