I would like to write an AppleScript that wo开发者_如何学编程uld allow me to launch iTunes with a given Library instead of having to hold down the Option key and browsing for one. I'm already aware of Doug's Library manager, which is not quite what I want. The AppleScript would be for a specific library.
iTunes doesn't allow you to do this with AppleScript, but you can write directly into iTunes' preferences, where it stores a bookmark (alias) to the currently selected library (or nothing, if you're using a library in the default location).
First, you'll need to obtain the alias data for your selected library location. Open iTunes holding down the Option key, select your library and quit iTunes. Then, in Terminal, run:
defaults read com.apple.itunes 'book:1:iTunes Library Location' | pbcopy
This will copy the library alias data to the clipboard.
Finally, here's the script:
property otherLibraryLocation : "" -- paste location between the quotes
property libraryLocationPref : "com.apple.iTunes 'book:1:iTunes Library Location'"
-- first, quit iTunes if it's running
tell application "System Events"
if exists (application process "iTunes") then
tell application "iTunes" to quit
end if
end tell
-- then, set the location
do shell script "defaults write " & libraryLocationPref & " " & quoted form of otherLibraryLocation
-- uncomment the following line to use the default iTunes library instead
-- do shell script "defaults delete " & libraryLocationPref
-- finally, relaunch iTunes
tell application "iTunes" to activate
Paste the library location between the quotes in the first line of the script, and you should be all set. To return to the original library, uncomment the line including defaults delete
.
You can create a symlink from ~/Music/iTunes to your chosen directory path in a unix shell script (man ln). And an AppleScript can call a unix shell script by sending the appropriate message to the Terminal app.
精彩评论