Search the web
Sign In
New User? Sign Up
jsosa · JavaScript OSA-Talk
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Out of Memory; delete   Message List  
Reply | Forward Message #422 of 529 |
I'm trying to shove all the songs in my iTunes library into an array so
that I can sort them and then remove a ton of duplicates.

However, using the following script, I get an Out of Memory error when
I attempt to create the sort comparison function using new
Function(..). (The sort function is pseudo-documented here:
http://phrogz.net/JS/SortBy_js.txt and has been tested to work in other
JS UAs like Safari.)

function SortBy(){
var args = (arguments.length==1 &&
arguments[0].constructor==Array)?arguments[0]:arguments;
var body = "return ";
for (var i=0,len=args.length;i<len;i++){
var param = args[i];
if (typeof(param)=='string'){
var colName=param;
var sortAsc=1;
} else for (var colName in param) sortAsc = param[colName];
body+='a.'+colName+(sortAsc?'<':'>')+"b."+colName+"?-1:
a."+colName+(sortAsc?'>':'<')+"b."+colName+"?1:";
}
return new Function('a','b',body+0);
}
var itunes = MacOS.appBySignature('hook');
var bw = itunes.browser_window[1];
var pl = bw.view;
var songs = [];
for (var i=1,len=pl.tracks.length;i<=len;i++) songs.push(pl.tracks[i]);
var sortFunc = SortBy('name','artist','album'); // <-- Runs out of
memory here
songs.sort(sortFunc);
Core.message(songs[2].name);

(time passes)

So I got around that by hardcoding the sort function. Now I want to
delete the files. Since delete is a reserved keyword, something like
itunes.delete(song)
doesn't work. How do I use methods/Actions which are reserved keywords
in JS?
I'm trying:
itunes['delete'](song)
now, which at least compiles, but I'm not sure if that's the right call
method.

--
"When I am working on a problem I never think about beauty. I only
think about how to solve the problem. But when I have finished, if the
solution is not beautiful, I know it is wrong."
- R. Buckminster Fuller




Mon Dec 1, 2003 8:40 pm

rabyak
Online Now Online Now
Send Email Send Email

Forward
Message #422 of 529 |
Expand Messages Author Sort by Date

I'm trying to shove all the songs in my iTunes library into an array so that I can sort them and then remove a ton of duplicates. However, using the following...
Gavin Kistner
rabyak
Online Now Send Email
Dec 1, 2003
10:29 pm

... arguments[0].constructor==Array)?arguments[0]:arguments; ... I don't get an Out of Memory message. I don't have any iTune thingies, so I just tested with...
Arthur Knapp
admiralnovia
Offline Send Email
Dec 4, 2003
5:04 pm

... Hrm. This was with Script Editor...are you using Script Debugger or something else? After I wrote this message, I ran into various other areas where ...
Gavin Kistner
rabyak
Online Now Send Email
Dec 4, 2003
5:09 pm

... thingies, ... I tried it in both, it worked fine. I don't think the issue is with your SortBy() function, but rather with the .sort() method that follows. ...
Arthur Knapp
admiralnovia
Offline Send Email
Dec 4, 2003
9:17 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help