Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aznelementmaste

macrumors newbie
Original poster
Mar 24, 2008
23
0
I have an applescript thats supposed to execute when I press a button. Then, the applescript is supposed to get all the songs from iTunes, and then load the songs into a table view inside a drawer (the button opens the drawer and executes the applescript).

Here's the applescript:

Code:
tell application "iTunes" to get names of tracks

It does work. However, the table view doesn't load the tracks that the applescript gets. I've made a new file just for the drawer, and connected the table view's data source inside the drawer to an object that's the name of the file containing the code.

Here's the code:

Code:
- (IBAction)makeDrawerVisible:(id)sender
{	
	[drawer setLeadingOffset:0];
	[drawer setTrailingOffset:0];
	[drawer openOnEdge:1];
	
	[itunessongs initWithSource:@"/Users/ericlee/Desktop/Development/Xcode/Mac/StopWatch%20%5BWORK%20IN%20PROGRESS%5D/itunesmusic.scpt"];
	NSLog(@"Getting iTunes songs");
	
	[drawerTableView reloadData];
}

The drawer shows up, and everything...it's just the songs that doesn't show up.

Thanks for any help!
 

aznelementmaste

macrumors newbie
Original poster
Mar 24, 2008
23
0
Okay, thanks for the tip!

I've changed it so that it uses SB, and I love it! The only hard part is actually reading the iTunes.h file that was generated and trying to find the variable that contains all the tracks.

Does anyone know the variable that contains all the tracks?

Thanks!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Well, just from a cursory glance at the file, it looks like you'd have to loop through sources to find a source (iTunesSource) with kind==iTunesESrcLibrary. Then call libraryPlaylists on the source and look for a playlist with its class==iTunesLibraryPlaylist. Then you can call tracks on the playlist to get all tracks. HTH :)
 

hhas

macrumors regular
Oct 15, 2007
126
0
Does anyone know the variable that contains all the tracks?

You might like to take a look at objc-appscript. Aside from being better designed and more compatible than SB (unlike SB, appscript is designed to work as much like AppleScript as possible), it also comes with much better developer tools: ASDictionary and ASTranslate. For example, running the following AppleScript command in ASTranslate:

Code:
tell application "iTunes" to get name of tracks

produces the equivalent ObjC code which you can adapt to suit:

Code:
// To create glue:  osaglue  -o ITGlue  -p IT  iTunes

ITApplication *itunes = [[ITApplication alloc] initWithName: @"iTunes"];

ITReference *ref = [[itunes tracks] name];

id result = [ref getItem];

Incidentally, I've just added a couple of new iTunes-related examples that you may find of help, including an [unfinished] iTunesController project that shows how to retrieve playlist info and display it in NSTableViews via Cocoa Bindings.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.