How do I tell iTunes to search my Library for something?
Thanks for the input everyone. Kindall, your script gets the job done, but not 100% what I had in mind. I think I’ll tinker with getting the UI scripted. I thought that AppleScript did UI scripting. I’m coming from Linux, and trying to get my Mac Terminal (shell) the way I like it. I’ve setup aliases to pass files to my Mac applications. I wanted to setup so if I give iTunes a path to a file or folder, iTunes plays it. If I just give it a string, then it searches its library and plays the first thing it comes up with. So Kindall’s script will work for that. So now..if I type (in the shell): itunes Deftones iTunes will copy what it searched for into the scripting playlist and play the music. If I type: itunes deftones.mp3 it plays that particular deftones.mp3 from my current working directory. GREAT!
AppleScript does do UI scripting, but it’s an afterthought (because people kept complaining that you couldn’t do it even though it’s not what AppleScript is for) and it only works with the standard system UI controls. iTunes uses a lot of custom controls; if you run the UI Inspector on it, the main iTunes window is basically opaque to scripting; its only children are the scrollbars. As I said, you could do it by simulating clicking (the search field) and then typing (what you’re searching for) and then clicking (the play button), but this is fairly “fragile.” Frankly I find UI scripting somewhat of an abomination because it gives developers an excuse not to give their applications a proper scripting object model and dictionary. “Just use UI scripting!” Bleah.