Page 1 of 3

iTunes Help

PostPosted: Thu Dec 11, 2008 12:33 pm
by MikeLuck
I'm just getting into using scripts and need some help...

I just purchased a couple of Insteon Motion Detectors and what I am trying to do is place them outside and trigger an alarm. I have it working to trigger the backyard lights when motion is made after dark but I also want it to do is to run iTunes and play an alarm sound on one of my Airport Express units. I was even thinking of triggering a barking dog on a powered set of speakers in the garage kind of like the old X10 Rex.

I need help with a script that will:

1) run iTunes
2) select an Airport Express for speaker output
3) select an album or track
4) play

Any help is greatly appreciated.

PostPosted: Fri Dec 12, 2008 10:05 am
by jay (support)
Good news and bad news. Playing a specific track is really easy:


Code: Select all
tell application "iTunes"
   play track named "Leave It" of playlist "Classic Rock" with once
end tell


Bad news is after looking through the script dictionary, I don't believe you can control the output. All is not lost, however: many of us here on the forums use Airfoil, which is a great utility for directing ANY sound to Airport Expresses, Apple TVs, and even other computers. And, it's fully scriptable. So, if you were using it, this is what your script would look like:

Code: Select all
tell application "Airfoil"
   disconnect from every speaker
   connect to speaker "Whole House" --use the right speaker name here
   set (current audio source) to application source named "iTunes"
end tell
tell application "iTunes"
   -- obviously, use your track name and playlist here
   play track named "Leave It" of playlist "Classic Rock" with once
end tell


PostPosted: Fri Dec 12, 2008 10:31 am
by MikeLuck
Jay,

Thanks for the help. I do have Airfoil and I'll use that. I think I'll be looking into learning a whole lot more about Applescript to make Indigo that much more fun. Now' I'm looking for some good alarm sounds, dog barking sounds and who knows, maybe I'll find the sound clip from the movie Home Alone. :lol:

PostPosted: Fri Dec 12, 2008 6:08 pm
by ricks
Yeah, there are no applescript commands for directly controlling airtunes speakers within iTunes. Very frustrating. However, I've seen some references to checking "Enable access for assistive devices" in the Universal Access Pref pane and then using Applescript Graphic User Interface (GUI) Scripting (see here at apple.com). Supposedly, you then have access to the airtunes items in the drop down list in iTunes. It was bugging me how other applications were controlling airtunes speakers, so I had to find out. Unfortunately, I don't have the time or inclination right now to actually try it. I'm happy with Airfoil, especially since Airfoil gives me the ability to control the volumes of each speaker independently.

PostPosted: Tue Jan 13, 2009 3:08 am
by dinotwo
I would be interested in trying this Airfoil script but first I need to get simple scripts for iTunes. My little 3-line scripts broke with Indigo 2 or with an OS upgrade about that time.

We used a simple remote (IBM HD23A) and Powerhouse transceivers RR501.

The scripts were imbedded in Trigger Actions.

This script works in Script Editor, but returns "script error: iTunes got an error: Parameter error. (-50)" when Indigo runs the script:

tell application "iTunes"
activate
reveal last playlist
set shuffle of last playlist to true
set song repeat of last playlist to all
play last playlist
end tell

Each time I start to play the playlist I want to start with a random song.

Thanks for any help.

Carroll

Indigo 3.06
iTunes 8.02
OS 10.5.6

PostPosted: Tue Jan 13, 2009 9:24 am
by matt (support)
Hi Carroll,

I tried your script in an embedded Trigger Action and didn't see the error, so I'm not sure what is causing the error on your system. You might try deleting the first couple of lines from the script as I don't believe they are needed and might be causing the problem:
Code: Select all
tell application "iTunes"
   set shuffle of last playlist to true
   set song repeat of last playlist to all
   play last playlist
end tell

PostPosted: Tue Jan 13, 2009 12:22 pm
by Dino-Two
Hi Matt,

Right, not needed. First line brings iTunes to the front and the second line selects the playlist.

Still the same error with the embedded shorter script. Here's the complete error:

Error script error: around characters 106 to 124
Error script error: iTunes got an error: Parameter error. (-50)

(I tried to correct my email address & change my password, but locked myself out, so I created a new account. Sorry.)

Carroll

PostPosted: Tue Jan 13, 2009 12:41 pm
by matt (support)
Try commenting out the remaining 3 lines, one at a time, so you can see which line is causing the error.

PostPosted: Tue Jan 13, 2009 3:50 pm
by Dino-Two
The important one is causing the error, of course. Hee, hee....

play last playlist

Carroll

PostPosted: Tue Jan 13, 2009 4:04 pm
by matt (support)
Try this instead:
Code: Select all
play first track of last playlist

PostPosted: Tue Jan 13, 2009 4:22 pm
by jay (support)
Also, try:

Code: Select all
play playlist "NAME OF PLAYLIST HERE"


rather than telling it to play the last playlist in the list. Don't know if that's gonna make a difference or not...

PostPosted: Wed Jan 14, 2009 1:28 am
by Dino-Two
Actually that's where I started, and when that didn't work, I defaulted to last playlist, since that what it happens to be.

I've now determined that no line of any script executes from Indigo. I was probably looking at another playlist when I posted before that some lines were executing.

I've also determined that the way we run Indigo is what's causing the problem.

We don't run as Admin, so Indigo runs in a Standard User account.

Without doing anything, we can use our remote and two Powerhouse transceivers RR501 to control our devices.

Our iMac G5 usually runs 24/7, but when I start from scratch this is what I do:
Login to Standard User account indigo. Launch Indigo 3.app, and connect to the interface.
Quick Switch to our Standard User account.
I can now launch Safari and control our devices from our Control Page.
Or I can launch Indigo 3.app and connect to the Remote Server to control our devices. This is where I have been testing the Applescripts.

There are no documents saved in indigo, except for Indigo's stuff. So I imported some songs into iTunes there, so I could test the scripts in the indigo account. This script, embedded in a Trigger Action, works perfectly when executed from our remote:
Code: Select all
tell application "iTunes"
   set shuffle of last playlist to true
   set song repeat of last playlist to all
   play last playlist
end tell
Our MacBook Pro is set up similarly with the addition of a Guest account. We can control our devices from Safari or from Indigo 3.app by connecting to the Remote Server.

I hope there is a solution to allowing the scripts to run under this setup.

Carroll

PostPosted: Wed Jan 14, 2009 7:14 am
by BillC
Carroll,

If I understand what you're trying to do, Indigo Server is running under one account and your iTunes is on another account? If that's the case, you need to add the machine, account, and password to the "tell" command like this:


Code: Select all
tell application "iTunes" of machine "eppc://UserID:password@192.168.0.110"


You should be able to use the machine name (e.g., iMac.local) instead of the IP address. I believe the machine name or IP address after the @ sign is needed even if both the account with Indigo Server and the account with iTunes are on the same machine.

PostPosted: Wed Jan 14, 2009 8:02 am
by matt (support)
Hi Carroll,

I think Bill is correct. The problem in this case isn't Indigo failing to execute the AppleScript, the problem is if you are targetting iTunes running under a different user account than Indigo Server then you must use the 'tell app XX of machine XX' syntax. Note you might also need to enable "Remote Apple Events" in the System Preferences Sharing panel.

PostPosted: Wed Jan 14, 2009 12:46 pm
by Dino-Two
All three of these scripts
Code: Select all
tell application "iTunes" of machine "eppc://Carroll Frison:xxxxxx@127.0.0.1"

tell application "iTunes" of machine "eppc://Carroll Frison:xxxxxx@Carroll-Frisons-iMac-G5.local"

tell application "iTunes" of machine "eppc://Carroll Frison:xxxxxx@10.0.1.3"
return 'Can’t get application "iTunes" of machine "eppc://Carroll Frison:xxxxxx@yyy". (-1728)'

I got "Carroll-Frisons-iMac-G5.local" and "10.0.1.3" from the Sharing panel of System Prefs.

"Remote Apple Events" is enabled.

Also tried putting Carroll Frison in quotes and substituting my short user name.

Carroll