View Full Version : a script I'd like to see (hint, hint)
mayboy
07-29-2003, 11:49 PM
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
Doug Adams
07-30-2003, 08:25 AM
Why not just drag tracks to a playlist sorted by Date Added?
DeltaTee
07-30-2003, 08:58 AM
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.
m.r.m.
07-30-2003, 09:21 AM
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?
mayboy
07-30-2003, 12:14 PM
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
DeltaTee
07-30-2003, 01:15 PM
You cannot change the double click action via scripting.
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 ?
Doug Adams
07-30-2003, 02:47 PM
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)
think there's an issue with your link doug...:eek:
Doug Adams
07-30-2003, 03:20 PM
think there's an issue with your link doug
Fixed above. THANKS deeg!
eustacescrubb
07-30-2003, 03:43 PM
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?
DeltaTee
07-30-2003, 04:46 PM
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.
Doug Adams
07-30-2003, 05:23 PM
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.
DeltaTee
07-30-2003, 07:39 PM
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
M.I.E.
12-06-2008, 11:07 AM
The script you provided, deeg, works great. Thanks! :) I even managed to bind keyboard shortcut (command-d) to the script using the instructions shown at tunequest. I suppose you could get it done with a mouse too by using xGestures for example.
I have one question though. How would you go about editing the script if you wanted the selected song to be added into a specific, named, playlist instead of the playlist of the song currently playing? For example playlist called myPlayList? I know the script is all in English and it shouldn't be *too* difficult to figure out but I still can't seem to get it done and working. ^_^; But anyways, thanks again for the script.
EDIT: Ups! Didn't realize it was such an old thread. ^_^;
S2_Mac
12-06-2008, 05:19 PM
It can be as easy as:set destination_playlist to playlist "myPlayList" You can also get a "playlist object" on-the-fly; here's a real simple version of your script:tell application "iTunes"
if the selection is not {} then
duplicate item 1 of the selection to playlist "myPlayList"
end if
end tell
P'bly a good idea to start a new thread ;-) Post the code you've got, and start describing your troubles....
M.I.E.
12-08-2008, 02:11 PM
Hey, thanks for the help! Now I have the perfect script for what I need! :)
I used the code you gave me:
tell application "iTunes"
if the selection is not {} then
duplicate item 1 of the selection to playlist "myPlayList"
end if
end tell
and figured out that if I change it to 'copy selection to playlist "myPlayList"' instead, I can add multiple items too. :) Thanks again!