Can I play a sound on motion detection?

Posted on
Wed Nov 05, 2003 7:59 pm
Joris offline

Can I play a sound on motion detection?

Hi,

I'm totally totally new at this.

Is it possible to record a sound and let it play when a motion is detected using Applescript? I would like to let iTunes play a barking dog sound :)

Joris

Posted on
Wed Nov 05, 2003 8:08 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Can I play a sound on motion detection?

Joris wrote:
Is it possible to record a sound and let it play when a motion is detected using Applescript? I would like to let iTunes play a barking dog sound :)

I know iTunes is very scriptable, so this should work. But, I don't know much about the specifics of scripting iTunes. You might take a look at this excellent site:

http://www.malcolmadams.com/itunes/index.shtml

Doug has put together excellent iTunes AppleScript info along with some basics to get started using AppleScript.

regards,
Matt

Posted on
Wed Nov 05, 2003 8:56 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

Here's an attachment. Just save this script in your attachments folder then create a trigger and put in the applescript area PlayTune("Your Song Name"). This should play the song that you specified. I would recommend that you keep iTunes open or it will have to launch it each time which will delay the song.

--[url=applescript://com.apple.scripteditor/?action=new&script=on%20PlayTune(myTrack)%0A%09tell%20application%20%22iTunes%22%0A%09%09set%20myTrackList%20to%20(get%20every%20track%20of%20playlist%201%20where%20name%20is%20myTrack)%0A%09%09play%20(get%20first%20item%20of%20myTrackList)%0A%09end%20tell%0Aend%20PlayTune]Click here to open this script in a new Script Editor window[/url].

on PlayTune(myTrack)
     tell application "iTunes"
          set myTrackList to (get every track of playlist 1 where name is myTrack)
          play (get first item of myTrackList)
     end tell
end PlayTune

[enter your name here]

-------------------------
[This script was automatically tagged for color coded syntax by Script to Markup Code]

Posted on
Wed Nov 05, 2003 9:14 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

gregjsmith wrote:
Here's an attachment.

Thanks Greg! And that Script to Markup Code script is awesome. Just what I needed for forums posts.

regards,
Matt

Posted on
Wed Nov 05, 2003 10:29 pm
Joris offline

(No subject)

Thanks guys!

I will start to build my first 'smart house' using this script :)

Posted on
Sun Nov 23, 2003 8:51 pm
egrass offline

Can't make the sound script work . . . .

This is exactly what I need! A sound script! But it doesn't work for me!

Can you give a little more direction on how to set this up? I save the script, and edit to put in my sound file but it doesn't work. What are the variables in the applescript? I am very much an applescript beginner, though I understand basic programing concepts.

Thanks for any thoughts you care to share.

Ed

Posted on
Sun Nov 23, 2003 8:57 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

(No subject)

Hey Ed, you shouldn't need to modify this script at all. As long as the song you want is in your iTunes Library it will get it. This is an attacement script so you need to save it in your attachements folder and make sure Indigo has loaded it. Then use it in a trigger by putting the following in your applescript area:

Code: Select all
PlayTune("Your Song Name")


Replace Your Song Name with whatever song you are looking for.

Posted on
Mon Nov 24, 2003 7:30 pm
egrass offline

I'm still too dense

Sorry to remain so dense.

I took the script you suggested and modified it as follows in the AppleScript editor to match a sound file in my iTunes

PlayTune("doorbell-1")

(I get an error when I try to play this from the editor. I am running OS10.3)

I saved it as a script file called doorbell.scp to the attachments area of Indigo and it shows up in my Indigo menu.

I set up a known working trigger action (remote control rf button) to the action of execute the applescript file. Nothing happens.

I put the actual text PlayTune("doorbell-1") in the embedded section in Indigo. Nothing happens

Apple brand applescripts are running so there is no problem there.

Sorry to be so dense. I must be missing something obvious here.

Care to offer any more thoughts? Your thoughts have been appreciated.

Regards, Ed.

Posted on
Mon Nov 24, 2003 7:58 pm
gregjsmith offline
Posts: 946
Joined: Apr 01, 2003
Location: Rio Rancho, NM

Re: I'm still too dense

This programming stuff can be difficult to grasp. Don't worry if you don't get stuff the first time around.

egrass wrote:
I took the script you suggested and modified it as follows in the AppleScript editor to match a sound file in my iTunes

PlayTune("doorbell-1")

(I get an error when I try to play this from the editor. I am running OS10.3)


You don't want to modify the script at all. You did everything correct except that part. Re-save the script in it's original form without modifications and and try your trigger again. I just want to be clear, don't modify the script.

Posted on
Mon Nov 24, 2003 9:04 pm
egrass offline

It works

Thanks, it worked great! I also got it to play Silvio by Dylan. I guess it thought the doorbell-1 was some kind of variable.

Care to answer one more charity question? I thought I could change system volume by saying

set volume 10
PlayTune etc
set volume 3

It seems to move the volume up AND down before playing. I need this to make sure my doorbell sound goes off at full volume even if the system volume was set low and then turn the volume back down. Any thoughts what I am doing wrong here? Even if I take out set volume 3, the command to set volume 10 only gives me about half volume. Set volume x with higher numbers are ignored.

Many thanks again, Ed.

Posted on
Wed Feb 04, 2004 1:24 pm
Guest offline

.mp3 over iTunes

Hi folks. Any way to play/launch an .mp3 without interfering with the work iTunes is already doing??

My home Audio system is being fed audio from the Macintosh iTunes. Kind of "full-time". I plan to have Indigo sense motion from a motion detector and fire off the appropriate script. I was going to program that module's appleScript to play a short .mp3 file kind of like a doorbell.

The trick for me, is that if I use the iTunes script (GREAT script by the way :) ) the iTunes "switches to" that .mp3. Nope. Not what I want. I want an "additional" .mp3 to play. The Mac will play it. The speakers will play it. I just can't figure out how to fire it without interrupting the music goin on. Ideas?

Ian

Posted on
Wed Feb 04, 2004 1:28 pm
ian@iansears.com offline
Posts: 15
Joined: Feb 04, 2004

play sound trigger

Whoops.

Just read this other topic reply. Ignore that last post (I made it without being logged in, sorry).

http://www.perceptiveautomation.com/phpBB2/viewtopic.php?t=11

Ian

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 26 guests