Categories: Misc / DotNet / Java / Coder / Linux / PHP Ask - La ask - La Answer

a script Id like to see (hint, hint)

iTunes would be the end all of all music players for me except for one small thing. I would like a jukebox mode. What I would like to see (and I am hoping some kind applescript guru out there <hi Doug!> will knock out some code) is as simple as having a script that, when running, will allow you to double click on a song and just add it to the bottom of a (predefined?) playlist.

This way, someone could come along to my laptop that is serving up music to my stereo, and just choose some songs which will be added to the list without disturbing the currently playing song. When the curent song is done it will continue down the list, just like a jukebox.

Now THAT would be cool!

TIA

Tim
[729 byte] By [mayboy] at [2007-11-9 13:03:20]
# 1 Re: a script Id like to see (hint, hint)
Why not just drag tracks to a playlist sorted by Date Added?
Doug Adams at 2007-11-15 17:25:12 >
# 2 Re: a script Id like to see (hint, hint)
iTunes is not really designed for this very well (even with a script). How would you stop someone from double clicking a song to start it playing?

The easiest way (depending on number of songs) might be to use the finder as a browser and write a small script that adds the song to a given playlist. Associate this script application with mp3, and double clicking a song would add it to the playlist which iTunes is playing through in the background.
DeltaTee at 2007-11-15 17:26:11 >
# 3 Re: a script Id like to see (hint, hint)
not that i understand the workings of these progs, but why is it that hard to do? winamp gives you the choice of either playing the song at once or enqueueing it as default action (for double clicking). no option in itunes to do this?
m.r.m. at 2007-11-15 17:27:08 >
# 4 Re: a script Id like to see (hint, hint)
Delta,

The idea is to double-click a song, but instead of it playing it gets queued up in the currently playing playlist.

Doug- I just thought it would be more intuitive for other people (when I have friends or family over) to just double-click a song. There are too many things that can go wrong if people are trying to drag songs, though it is a simple work around.

Obviously I have the barest minimum understanding of applescripting and I greatly appreciate any effort someone might be willing to put into giving this a spin. The way I envision it working would be to start playing a song from any given playlist, then activating the script, which until it was deactivated would add songs to that playlist rather than play when double-clicked.

Thanks again,

Tim
mayboy at 2007-11-15 17:28:10 >
# 5 Re: a script Id like to see (hint, hint)
You cannot change the double click action via scripting.
DeltaTee at 2007-11-15 17:29:09 >
# 6 Re: a script Id like to see (hint, hint)
you could use something like xkeys (available from versiontracker.com) to invoke the script via a pf key or some such rather than double clicking on it.. then something like..

tell application "iTunes"
set fx to fixed indexing
set fixed indexing to true
set thisPlaylist to (get view of front window)
if selection is not {} then
copy selection to selectedTracks
else
copy every track of thisPlaylist to selectedTracks
end if
set activeplaylist to container of current track
repeat with thisTrack in selectedTracks
duplicate thisTrack to container of current track
end repeat
set fixed indexing to fx
end tell

would add the selected track/s or the whole playlist you are currently viewing if there is no selected tracks to the playlist of the current playing track.. sorting the playlist into the order added would require you to sort the playlist by column 1.. might need to add some checking regarding the nature of the current track.. not alot of point adding it to a radio stream for example..

as an aside.. making use of context menus in script editor to add code snippets (such as doug's selected track grabber used here) makes writing these scripts on the fly so much easier... Doug.. remember that thread about reuseable code snippets on the old board ? wonder if its worth recreating it here ?
deeg at 2007-11-15 17:30:19 >
# 7 Re: a script Id like to see (hint, hint)
remember that thread about reuseable code snippets on the old board ? wonder if its worth recreating it here.

Funny you should say, I was just going through some of those up here at the house. Here be the link to it: Script Editor 2 Templates (http://www.xsorbit1.com/users/itunes/index.cgi?board=discuss&action=display&num=1044203173&start=2)
Doug Adams at 2007-11-15 17:31:20 >
# 8 Re: a script Id like to see (hint, hint)
think there's an issue with your link doug...:eek:
deeg at 2007-11-15 17:32:13 >
# 9 Re: a script Id like to see (hint, hint)
think there's an issue with your link doug

Fixed above. THANKS deeg!
Doug Adams at 2007-11-15 17:33:20 >
# 10 Re: a script Id like to see (hint, hint)
Doug and deeg. Never thought about it before, but you guys sound like a team of some kind. :)

Say, is there any way to have one AppleScript import another as a function when it opens? I was thinking the other day how useful it would be to have an AppleScript Library containing all the routines we use over and over again so we could call them as functions from one place - you know, sort of the way one can link to external JavaScripts in an HTML document?
eustacescrubb at 2007-11-15 17:34:21 >
# 11 Re: a script Id like to see (hint, hint)
A Library of functions is possible, but it is not as clean as I would like. (For a person trying a generic solution do a web search for ASLoader.)

I have a suite of scripts for handling Yahoo! Groups mail in Entourage. It loads a library at the beginning:

property yghLibraryFile : (path to current user folder as text) & "Library:Application Support:Plaid Cow Solutions:YahooGroupsHandler:yghLibrary.scpt"
set yghLibrary to load script (alias yghLibraryFile)

and then allows for calls to the Library, ie:

set theContent to yghLibrary's cleanMessageContent(content of theMsg)

This works very well. :-)

I have been planning to do one for iTunes, but I haven't actually worked on any of my iTunes scripts in several months.
DeltaTee at 2007-11-15 17:35:19 >
# 12 Re: a script Id like to see (hint, hint)
Say, is there any way to have one AppleScript import another as a function when it opens

Create script objects (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.14.html) . Script objects are like sub-routines but stored in separate files, which you can save and then load (as libraries, as DeltaTee alludes to above), like "require" in Perl.
Doug Adams at 2007-11-15 17:36:20 >
# 13 Re: a script Id like to see (hint, hint)
I think making the library scripts into a script object would add an unecessary level of redirection. Loading the script effectively creates a script object, without writing the code as a script object.

Or maybe that was what you meant anyway. (It's been a long day.)

btw, I had to switch to my default username everywhere else since "Plaid Cow Solutions" is too long for this bbs.

randy
DeltaTee at 2007-11-15 17:37:26 >
[an error occurred while processing this directive]
[an error occurred while processing this directive]