Introduction: Create an Applescript/Arduino Alert Flag.

Picture of Create an Applescript/Arduino Alert Flag.

Have you ever felt like the mail sound on your Mac just wasn't enough? Simple sounds and alerts just don't cut it for you? You want something more apparent and rewarding? If so, this is the Instructable you've been looking for.

In this Instructable, I'll show you how to hook up your Arduino to your Mac and throw up an actual flag when the alert of your choice occurs. In our example, we'll be doing an email alert, but you can use AppleScript to call this when almost anything happens.

I've created a little Instructables flag to go off when I receive comments on my instructables.

Let's get started!

Step 1: What You Need

Picture of What You Need


An Arduino: I know at least that the Duemilanove and the Diecimila will work. I don't know if older board versions will work.

A Flag: I made an instructables flag to alert me when I get instructables comment.

A 47 Ohm resistor: This is to prevent the Arduino from resetting at the close of a serial connection

A Servo

Wires to connect the Arduino to the Servo. My wires were a bit longer than needful.


Tod Kurt's Arduino Serial C code. Tod put this code up which makes it tremendously easy to communicate with the Arduino. Files included here. For more info look here:

- Arduino Code

- Run Flag Applescript

Step 2: Setup the Arduino

Picture of Setup the Arduino

We need to get the physical side of this equation set up first.

Out of the Servo, There are 3 wires: Voltage, Ground, and Control. In this setup, we're plugging those into 5v, Ground and Pin 9.

Also, we're going to put a 47ohm resistor into the 3v3 pin and the reset pin. This will prevent the arduino from resetting every time there's a serial connection closed. This was a real pain for me to deal with early on, I'd written the software to handle the reset with a delay, but it wasn't ever working the way I wanted it to. Resistor solves that problem easily.

Note: According to the source I got this from, the Resistor causes an excessive 20mA current in the Arduino when the reset button is pressed. The person who tested it said it's outside of specifications, but still worked. Avoid resetting the Arduino when you have the Resistor is connected.

Load the included software onto the Arduino. Make changes as you see fit. Essentially, you're sending a 0 or a 1 to the arduino, and it's going to turn the flag up or down based on that.

Step 3: Setup the Servo & Flag

Picture of Setup the Servo & Flag

Tape Flag to pole.
Tape pole to the servo

...Pretty simple.

Step 4: Setup Software Communication

Picture of Setup Software Communication

First, you'll need to compile Tod Kurt's Arduino serial communication script. This is super easy.
Open up the terminal and navigate your way to where you have the arduino-serial.c file
Type in the following:

gcc -o arduino-serial arduino-serial.c

Once it's done compiling, type:
and it should print to the screen usage information.

Let's test out our Flag. In the terminal, navigate to where your newly made arduino-serial script and type in the following:

./arduino-serial -b 9600 -p /dev/tty.usbserial-A4001lGx -s 1

You'll need to substitute your Arduino's serial port. If you're not sure what this is, go into the Arduino software, and look under Tools->Serial Port. The order is important here. The -b is baud, and must be set before the port (-p) is set. -s is the message to be sent.

This should raise the flag, You can lower it by changing the "1" at the end of that line to a "0"(zero)

Once that works, the next thing is to setup the associated AppleScript. With this Applescript, you're going to have to tell it where everything is. For ease, I stuck everything in the same spot, namely: ~/Library/Scripts/ , of course you can use whatever you'd like.
Once you've got your Applescript setup, give it a go by pressing that big green "run" button at the top.

One more thing and we're set. Now we need to setup to run the Applescript.
Open up Mail and go into the preferences.
Select Rules
Add a Rule
In the rule, set the conditions as you like. For me, I've setup the rule to have the "from" address contain "", so it will fire when I receive anything from Instructables.

You're finished! If you have a method of testing it out, give it a shot.

Step 5: Final Thoughts

You don't have to use to take advantage of this, obviously. You can fire the script from any application that will access Applescript, including the Finder.

Windows users: I'm not familiar enough with Outlook to know if you have ways to triggering script execution, but I imagine someone here would have no problem figuring it out.

Because of the way Applescript is executed, the delay in the script will stop everything from happening while it waits. I haven't explored fixing this yet, but I imagine it would be done on the side of the Arduino, rather than the Applescript. For instance, send two parameters to the Arduino: The up/down bit, and a duration...

I hope you've enjoyed the Instructable. I put it together to see if I could figure out a little bit more about interacting with the real world from the computer world.


App For Tradies (author)2016-01-18

Pretty cool idea.

technoBot319 (author)2015-01-16

My servo doesn't move when I enter the command in the terminal. Can someone help me?

vishalapr (author)2011-07-24

when I download runflag it downloads and saves as an unknown file type so what do I need to select to open it?
I tried adobe application installer but it didn't please help!

aarone (author)vishalapr2011-07-24

runflag is an applescript file. If you're using it on Windows, it won't work.

The applescript simply calls runs the C script which puts the flag up. Depending on what email client you use, you may be able to write a script for that which will run the same C shell script in windows.

vishalapr (author)aarone2011-07-24 is there any way we can do thisbut on windows XP?

aarone (author)vishalapr2011-07-24

You would be able to use to c script, but not the Applescript. You. Would have to find a way to call the c script from within your email client.

vishalapr (author)aarone2011-07-24


vishalapr (author)2011-07-24

Is it possible to use this method but for windows XP...hope there is...I would really love any help on this!

peter_schlamp (author)2011-03-19

Excellent post. This will be my first servo project!

sparkyish (author)2010-12-01

great write up, thanks a ton. I am very new to this. I am using arduino to control a dc motor, and i wanted to make a voice command script recognized by speech recognition + applescript to run an appropriate forward or backward movement. i had the arduino portion set up and working by entering either an f (for forward) or b (for backward) in the serial monitor of arduino, but after i compiled Tom Kurt's code following your instructions the motor no longer turns. I can send the character f or b through terminal and it successfully makes it through to arduino (proven through a serial.println to the serial monitor), but no turn on the motor.. do I need to setup another serial port?

here is my test terminal command:
./arduino-serial -b9600 -p /dev/tty.usbserial-A700dYg4 -s f

results in: "Running forward" in the serial monitor

and here's my arduino code:


AF_DCMotor motor(2, MOTOR12_1KHZ);

void setup() {

void loop() {
if (Serial.available() > 0) {
switch (inByte) {
case 'f':
Serial.println("Running forward");;
case 'b':
Serial.println("Running backward");;
Serial.println("default value reached");

thanks for your time/advice!

sparkyish (author)sparkyish2010-12-01

edit.... and after all that i noticed the ground came unplugged. lucky me for easy solutions! thanks again, haha

aarone (author)sparkyish2010-12-01

Glad to hear it's working! Be sure to detail in a blog or something so we can all take a look when it's done :)

Mansan (author)2010-11-11

Hi, cool project, I have been searching a lot for something that does this!

I have this weird problem though, the Arduino only responds properly if the IDE and serial monitor are open, otherwise I just get a quick double blink from the LED. How can this be?


Mansan (author)Mansan2010-11-11

Also, I'm using an Arduino Uno.

aarone (author)Mansan2010-11-11

Hmm, that's a bit of a tricky one.

I haven't looked very hard at the Uno's reset. I know they made some changes to engage the reset which is probably why your setup isn't working right. On the Arduino, the board resets automatically when a serial connection closes. In my setup the resistor on the reset pin holds it high to prevent it from resetting.

If the reset on the Uno is different, it may be what's preventing this from working.

bfarn (author)2010-10-05

Just wanted to make your flag pop up.

And to thank you for this project. I'm using it to control a simple status light on an applescript and photoshop-action based photo booth.


anonymouse197 (author)2010-07-28

Thanks for a fantastic instructable! Being a bit of a novice I was wondering how I could do away with the servo and flag (as my servo has not yet arrived) and simply light the Arduino LED for a couple of seconds. I originally though that this would simply be as easy as replacing every servo related command with a corresponding LED pin 13 one, but I have got a bit confused with the command line aspect. Please could you give me a hand with the Arduino scripting and command line? Thank you very much for your help and a great instructable, Ari

Ah Ha! Its OK, I have figured it out. :)

bobbob (author)2010-05-15

I put the file in the correct folders but I get this error:
sh: /Users/drummerboyx/Library/Scripts/arduino-serial.c: Permission denied

Any ideas?

aarone (author)bobbob2010-05-15

From there error, it looks like you didn't compile the script, or you put the c source code into your runflag script instead of the executable file. In the runflag.scpt file, look at the lines:

./arduino-serial -b 9600 -p /dev/tty.usbserial-A4001lGx -s 1

and see if they don't read something like:

./arduino-serial.c -b 9600 -p /dev/tty.usbserial-A4001lGx -s 1

if you did end up compiling your executable as a .c file for some reason, you can change it's permissions in the info window of the file. Select the file in the finder and choose "Get Info".

humphreys7 (author)aarone2010-05-19

 How do you compile it?

humphreys7 (author)humphreys72010-05-19

never mind, figured it out

and for anyone else who doesn't know how:

 gcc ./arduino-serial.c

aarone (author)humphreys72010-05-19

specifically, it's
gcc -o arduino-serial arduino-serial.c
The -o flag directs the output to a particular file.

Glad you figured out. Hope you find it successful

I've been considering redoing the instructable. The applescript should be sending a single command, and the arduino handling it on the otherside based on that. That would make for a smarter program.

glocketz (author)2010-03-08

 Hey there. Great project. Im having problems downloading the script file and the .pde. They just show up as .tmp files on my desktop. Thoughts?

aarone (author)glocketz2010-03-08

This is just a file issue between the site and your browser. If you rename the files with the appropriate extensions, they'll work fine :) (they're just text files...)

glocketz (author)aarone2010-03-08

 thanks for the quick response. everything works great. Im a bit new to avr programming, and im wondering if you can help me. Im using the project for an application that needs the servo to rotate 180deg in the positive direction and stop. then, when receiving a "1" command, rotate again 180deg in the positive direction, etc. Can you help me augment your .pde? 

aarone (author)glocketz2010-03-16

Sorry, I just realized I hadn't answered this. You should be able to do something like what you're describing, but I don't think I can help you. To make what you're describing, it sounds like you'll at least need a full-rotation servo. I don't think my Arduino program is very well suited for what you want, but it shouldn't be too difficult to write something like this. You may want to swing by the arduino forums and see if they have some suggestions. Be sure to be detailed in what you're trying to do, and good luck!

Leandro Tavares (author)2010-01-17

Hello, first of all, congratulations for this project!

I tested the terminal part, and it worked, but when I tried the AppleScript part I got an error message: "sh: /Users/leandrolucianitavares/Library/Scripts/arduino-serial: No such file or directory". I created the folder "Scripts" at the Library Folder, and put both the arduino-serial.c and the AppleScript file(which i called LedArduino) into it. I tried everything i could tought to solve it, but it was not effective! Could you help me? 


Leandro Tavares

aarone (author)Leandro Tavares2010-01-17

Hmm, this can be a toughy...

I'd double check that you've put the Applescript into your user's library folder and not the library folder at the root of the system. That is:
Make it's in:

and not

Secondly, in your Mail rule, make sure that the path is properly set. In my example, I wrote 

The tilde (~), if you're unaware is a shortcut to your user directory. If it's not there, Mail will try to look for the script at the root level, (Just /Library/Scripts/ ) and it's not there...

I hope that helps. If you still have problems, PM me and we'll talk more details...

Leandro Tavares (author)aarone2010-01-17

 Thanks for your time and the support, I made a mistake when I put the files, I forgot to put the compiled arduino-serial, I only put the arduino-serial.c, it was a dumb mistake!

By the way, I am expanding it for other applications (Adium as an example), but I am using LEDs instead of servos! I am thinking about a push button to turn off the LEDs (representing that the message was received) !

I was looking for a project like this!!
Again, thanks for this!!!

Leandro Tavares

aarone (author)Leandro Tavares2010-01-17

 You're very welcome, Thanks for being interested in my project! 

A push button to turn "off" is great. Make sure you have debouncing in there to make it work properly. It's also occurred to me that putting the "off command" into the Arduino via hardware, such as two connected pins would be great. One set to high output, the other reading for a high or low output, or if that pin wasn't set, then you could wait for software command to send the "off" signal. 

Good luck with your project. I'm glad you found a solution, and glad you found this useful!

mutface (author)2009-09-07

files dont download, all i get is .tmp : (

aarone (author)mutface2009-09-08

This has something to do with the Instructables site. Fortunately, there's an easy workaround. Just change the .tmp to a .c or a .pde and you'll be able to open the file. It's just text in there anyway.

mutface (author)aarone2009-09-11

thanks! it worked great

aethiolas (author)2009-03-31

I just wanted to throw the flag up!! Awesome job!

munchman (author)2009-03-12

For windows, you could get an outlook rule to trigger the arduino.

=SMART= (author)2009-03-12

Cool !

NachoMahma (author)2009-03-12

. Awesome! I don't need that particular implementation, but I can see where this could be adapted for all sorts of useful things. . Would it be possible to leave the flag up until you open the msg? Some other event, eg, mouse click?

aarone (author)NachoMahma2009-03-12

I'm not sure. The Applescript dictionary for Mail is cool, but fairly limited. I don't think it attaches to specific messages. Potentially though, one could write a script that would fire when messages are received and watch those messages waiting for one to be opened. It's just not available out of the box.

Swishercutter (author)2009-03-12

How about a pirate flag, since most people use their computers as "pirate ships".

Make it pop up whenever the bit torrent client is running.

aarone (author)Swishercutter2009-03-12

Absolutely. I know at least one Torrent client supports Applescript. If it has the proper hooks, I'd set it up to fire when a Torrent was completed.

gmjhowe (author)2009-03-12

This is great! I would love a little flag that pops up. But i check Ibles so often..

WirelessMonk (author)2009-03-11


About This Instructable




Bio: I'm Aaron. I've written for Television I"ve written, directed, and performed in a musical I'm a programmer I'm a Roboticist ... More »
More by aarone:Create an Applescript/Arduino Alert flag.Build an inexpensive Ikea NAS/Computer
Add instructable to: