Applescript to launch iTunes with a specific library

最后都变了- 提交于 2019-12-09 13:09:35

问题


I would like to write an AppleScript that would 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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1693780/applescript-to-launch-itunes-with-a-specific-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!