What you have to do is to add the commands you want in what I sent you:-
set arduinoPort to "/dev/cu.usbmodem1d11"
-- this opens the port and resets the arduino
set arduino to serialport open arduinoPort bps rate 9600 data bits 8 parity 0 stop bits 1 handshake 0
if arduino is equal to -1 then
display dialog " could not open port "
else
repeat -- repeat forever
-- wait until something is sent
set bytesIn to 0
repeat until bytesIn is not equal to 0
set bytesIn to serialport bytes available arduino
end repeat
set cmd to serialport read arduino for 1
set cmds to cmd as string
-- display dialog "Command recieved = " & cmds
if cmds is equal to "1" then
display dialog "Command 1 recieved"
end if
if cmds is equal to "2" then
display dialog "Command to quit recieved"
exit repeat
end if
end repeat -- of the forever repeat
-- note this next bit will reset the arduino
serialport close arduino
end if
So instead of having
display dialog "Command 1 received"
You put what you want to so when you get an ASCII 1 from the arduino. You might want to put:-
tell application "iTunes"
tell (track 1 of playlist "normal") to play
end tell
in place of this line. Also you add other commands, depending on what you want to do:-
if cmds is equal to "A" then
display dialog "Command A received"
end if
This will respond if the arduino sends an ASCII 'A'