Re: Controlling iTunes Remotely
Re: Controlling iTunes Remotely
- Subject: Re: Controlling iTunes Remotely
- From: "Johnny AppleScript" <email@hidden>
- Date: Sun, 20 Jul 2003 08:19:17 -0600
On 03/07/20 07:14 AM, "Matthew Smith" <email@hidden> wrote:
>
What happens when you select a track and run a script that says:
>
>
tell application "iTunes"
>
selection
>
end tell
In iTunes 4.0 when the selection is inside a shared remote library list I
get:
--> {}
Works fine on any selection in a local user or library play list. Must be a
bug fixed or feature added in 4.0.1; I'm not ready to upgrade as I am
content to use my worldwide access to my own shared library at home until I
can upgrade servers, clients and add needed hacks to restore v4.0
functionality at the same time. (:
So, anyway to your problem...
>
Why should I be reading an XML file? I have something that works most of the
>
time. Trying to parse an XML file would be a pita.
Sorry for thinking out loud in an effort to be helpful.
If you can get the name OK, then all I can offer you is an earlier attempt
at remote scripting I found in my iTunes scripts library; this was
originally written during SoundJam/iTunes 2-3 days, and I just cleaned it up
with some help from JD to use a better method of identifying the file to be
played (I was forced into using 'open alias [location]' before).
I'm sure it's far more wordy and complex than you want, and you can probably
do much better than I did, especially if you can get more ID data from the
shared list item than just the name (disk location would be an ideal unique
identifier), but I think it at least helps you address both of the two
concerns you expressed originally; i.e., the call to library playlist 1
reads the entire library of items on the remote machine, regardless of
current playlist or browsing view; it will also present a list of choices
with additional criteria should you encounter identical track names; mine
also allows for searches with keywords when you can't recall the *exact*
name of a song -- handy for when you can recall any for-sure word(s) of a
song, but can't recall the extra garbage; e.g.: Jump In The Line (Shake
Sonora), I can only ever remember 'shake' or 'jump', and either of those two
keywords will return my desired choice in a list, or just play it if there's
only one that matches the keyword.
It's also quite nifty when you want to hear a particular song, but don't
care to even open iTunes and browse about. Just type in the name or keyword,
and off you go. Obviously, it's nice on a local machine for local play, too.
Here goes:
set theRemoteMachine to "eppc://192.168.1.xxx"
set theTrackToPlay to text returned of (display dialog "What track do you
want the iTunes server to play?" default answer "Enter track name or keyword
here")
tell application "iTunes" of machine theRemoteMachine
using terms from application "iTunes"
set theLibrary to library playlist 1
set targetTracks to every track of theLibrary whose name is
theTrackToPlay
set targetTracksCount to count of targetTracks
if targetTracksCount is 0 then
set targetTracks to every track of theLibrary whose name
contains theTrackToPlay
set targetTracksCount to count of targetTracks
end if
if targetTracksCount is 0 then my localDialog("Searched iTunes
Library on" & theRemoteMachine & return & return & "No tracks with the name
or keyword '" & theTrackToPlay & "' were found.")
if targetTracksCount is 1 then play item 1 of targetTracks
if targetTracksCount is greater than 1 then
set possibleChoices to {}
repeat with i from 1 to number of items in targetTracks
set x to item i of targetTracks
set {trackName, trackArtist, trackAlbum, trackYear} to
{name, artist, album, year} of x
if trackArtist is "" then set trackArtist to "?"
if trackAlbum is "" then set trackAlbum to "?"
if trackYear is "" then set trackYear to "?"
(* use any additional criteria you like to discern
differences between tracks *)
set trackInfo to trackName & " by " & trackArtist & " on " &
trackAlbum & " in " & trackYear
set the end of possibleChoices to trackInfo
end repeat
set myChoice to (my localChoose(possibleChoices)) -- as text
if myChoice is not false then
set finalChoice to {}
repeat with eachChoice in myChoice
repeat with i from 1 to count possibleChoices
if contents of eachChoice is item i of
possibleChoices then set end of finalChoice to i
end repeat
end repeat
finalChoice
log finalChoice
play item finalChoice of targetTracks
end if
end if
end using terms from
end tell
on localChoose(possibleChoices)
choose from list possibleChoices
end localChoose
on localDialog(message)
display dialog message
end localDialog
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.