Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to manage two music folders Apps
My iTunes music library has recently grown to 20 GB. This pretty much hosed the tiny 40 GB drive in my Powerbook. My solution was to move my ~/Music folder to an AFP server share named "MusicShare" (you could use a FireWire drive). I then renamed the "Music" folder on the server share to "ServerMusic." Finally, instead of a "Music" folder in my ~/home, I created a soft link named "Music" that pointed to the /Volumes/MusicShare/ServerMusic/.

But, I also wanted to carry 1 or 2 GB of MP3s with me when I was not at home. So I created a smaller "LocalMusic" folder in /Users/Shared/. I put it there so any logged-in user could play music from the same library. Then all I needed was a way to change the soft link "Music" in my ~/home directory to point to one or the other of the two "Music" folders.

So I wrote an Applescript that:
  1. Checks to see if iTunes is running;
  2. Gets the name of the current ~/home folder (so it works for all users);
  3. Determines if the server share (or Firewire drive) is mounted;
  4. Gets the correct path to the mountpoint (different for each logged-in user in the case of FUS); and
  5. Makes a new soft link in the current users' ~/home directory.
Read on for the script...

Enter this in Script Editor:
tell application "System Events"
  if not (exists application process "iTunes") then
    set short_name to do shell script ("id -un")
    tell application "Finder"
      if (exists folder "MusicShare:ServerMusic:") then
        set the_path to POSIX path of file "MusicShare:ServerMusic:"
        do shell script "ln -fhs '" & the_path & 
         "' '/Users/" & short_name & "/Music'"
      else
        do shell script 
         "ln -fhs '/Users/Shared/LocalMusic/' '/Users/" & 
         short_name & "/Music'"
      end if
    end tell
  end if
end tell
tell application "iTunes" to activate
Save the script as an Application called iTunes Script.app, paste an icon on it, and use the script in your Dock instead of iTunes. Don't forget to correct the permissions for both the script and the Music folders.

Now when I launch iTunes, the script checks to see if my server share is mounted. If so, iTunes opens my entire server music library. If not, iTunes opens my current favorites local music library. If iTunes is already running, it just brings iTunes to the foreground.

TIP: Plug your new Mac Mini into your home stereo system. Move your Music folder into your ~/Public folder and make a soft link back to ~/home. Then turn on Personal File Sharing. Now your home stereo and home office laptop can share the same music library.
    •    
  • Currently 3.25 / 5
  You rated: 5 / 5 (4 votes cast)
 
[29,889 views]  

An AppleScript to manage two music folders | 16 comments | Create New Account
Click here to return to the 'An AppleScript to manage two music folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to manage two music folders
Authored by: supretigre on Jan 26, '05 10:57:22AM

Genius hint, thanks!

I think I'll do the same, and also include a similar script in the startup items, to accommodate other applications that launch iTunes.



[ Reply to This | # ]
An AppleScript to manage two music folders
Authored by: ennonymous on Jan 26, '05 11:00:29AM

Exactly what I need. :) But:

Is there a way to synchronize the metadata (last time played, ratings etc.) between the local and server directories?



[ Reply to This | # ]
Metadata
Authored by: luhmann on Jan 26, '05 12:01:37PM

The fact that ratings aren't saved in the MP3 files themselves is one of the major reasons I don't use them. I also worry about synchronizing music I download to my laptop with the main list. I don't want to accidentally trash ITMS files that are only on my laptop.



[ Reply to This | # ]
An AppleScript to manage two music folders
Authored by: webbix on Jan 26, '05 02:25:53PM

I manage this manually in a similar way. iTunes still looks in the ~/Music/iTunes folder as the default location and that does not change. You can manage different libraries a couple of ways. the 'iTunes' folder can be a softlink to a driver that maintains the settings and would be the same no matter what you connected it to (I carry a FW drive with my laptop).

Alternatively you can just make an alias to the 'iTune Music' folder and the metadata and other settings stay with the machine so that they can also be used in a unique manner on another computer such as your desktop.

The only things I have found (other than ratings I suppose) is the custom EQ settings.

I also found that you can export/reuse those settings even on a Windows machine with iTunes. I found the iTunes directory on my Windows box and copied that metadata files over and all was retained. Including manually added Live365 streams and all playlists.

There should be no problem with losing any songs this way. If you use a laptop though, you would have duplicate copies of the songs of those on your server or external drive.



[ Reply to This | # ]
Somewhat related...
Authored by: DougAdams on Jan 26, '05 12:19:32PM
Somewhat related...The shareware AppleScript iTunes Library Manager, besides being able to manage multiple iTunes libraries, will allow you to have multiple designated Music folders by virtue of being able to manage multiple iTunes preference files.

(Full disclosure: I'm the author of iTunes Library Manager.)

[ Reply to This | # ]
Is this really needed?
Authored by: lullabud on Jan 26, '05 04:55:53PM

My iTunes music folder is well over the size of my Powerbook's internal hard drive, so I ran into this scenario long ago. My solution was what I think Apple intended, and that is this...

1) Go into iTunes prefs and click on "Advanced"
2) Click "Change" next to "iTunes Music folder location" and select the external disk drive or whatever you're using to store your music.
3) Click OK.

This will copy all of your music to the new location, but will leave the original Music folder in tact. (I've had problems with the Music folder location being changed back to the local disk, so keep an eye on that when switching between local and external locations when using iTunes.)

4) Go prune out the songs you don't want to keep on your local hard drive.

Now when you open iTunes it'll look in the new location first and then the local (original) location. If you don't have your external disk around you can still listen to the selection that you have stored in your local Music folder. When you rip new CD's or if you buy from the ITMS without the external disk the media gets saved to your local Music folder. To sync them, plug in your external disk and check that you still have the right external location in iTunes Prefs -> Advanced pane. Then hit "Advanced -> Consolidate Library" to copy all your local media in with your external disk library.

I've been using my rig like this for several months and it works great, I have all my Music stored in the Music folder on an external 80gb HDD.



[ Reply to This | # ]
Is this really needed?
Authored by: JohnnyMnemonic on Jan 26, '05 10:35:50PM

The problem is: say that you often move stuff from the external FW drive to the local drive, so you can take it with you. You then would have to manually repoint iTunes to each song moved to your local drive; a royal pain.

Unless someone has thought of a better way, I think this script is a cool way to allow moves between a fw hd and a local (frequently changed) cache.



[ Reply to This | # ]
A Demonstration of the Easier Route
Authored by: lullabud on Jan 27, '05 02:16:32PM

No, you're wrong. You don't have to point iTunes to the local files. here is a demonstration...

I have my music folder set in the iTunes prefs to be on an external 1394 drive that I will refer to as the "External Drive". I will call that the "External Music folder." The original Music Folder location in my home folder I will call the "Local Music folder."
I just did this test:

1) Copy a folder from your External Music folder to the Local Music folder.
2) Eject the External Drive and unplug it if possible.
3) Start iTunes and double-click on one of the songs that you just copied to your Local Music folder. It will play fine.
4) Hit CMD-R to reveal the file within your Local Music folder. See? It's there, and the External Drive isn't even plugged in.
5) Plug in your External Drive.
6) Play a song that is not within your Local Music folder, it will play fine.
7) Press CMD-R to reveal the file in your External Music folder.
8) Go into iTunes Prefs -> Advanced and notice that iTunes has the Local Music folder set as the location of the "Music Folder". (Don't change this.)
9) Cancel out of the preferences window and restart iTunes.
10) Go back into iTunes Prefs -> Advanced and you will see that iTunes has set the "Music Folder" location back to your External Music folder automatically.
11) Play the same song you were just playing from your Local Music folder. It will of course play.
12) Press CMD-R to reveal it in your External Music folder.

This demonstration proves that it DOES in fact work, and without some extra applescript to handle it all. Give Apple some credit, they did a great job, better than some of their biggest fans even know. I'm constantly amazed when I find little tricks like this that make things so much easier than I thought they would be.



[ Reply to This | # ]
A Demonstration of the Easier Route
Authored by: brainsik on Jul 01, '05 03:02:10AM

FWIW, I tested this on iTunes 4.9 (Tiger) and it worked.



[ Reply to This | # ]
A Demonstration of the Easier Route
Authored by: greenman on Nov 10, '05 10:45:34AM

it doesnt solve the following problem:

after working with the local folder...and adding new tunes to the local folder.....saying the goal is to have ALL your music on the external folder (for backup purposes) .......its not so easy to add all new tunes from the local to the external folder because you dont know them all in your head......apart from the fact that in my external drive there are folders like: 2003, 2004 and then inside drum&bass, soul, house...whileas in itunes there are folders named by artists after i bought songs



[ Reply to This | # ]
Is this really needed?
Authored by: landis on Jan 28, '05 02:14:50PM

Love the script idea, but would much prefer a built-in Apple method in order to avoid any long-term problems with updates. So, I tried this suggestion out.

I was running out of disk space on my system drive and have an external Firewire that's always mounted. I followed your suggestion to change the music library from the Advanced preference pane, but iTunes didn't automatically transfer my music for me. I'm copying it manually now and will post back if I have any other problems with this method.



[ Reply to This | # ]
Would this work with samba shares?
Authored by: schiznik on Jan 26, '05 11:14:21PM
I'm trying to set this up between my linux server and my powerbook.

At the moment, Im only using samba on my win/lin/mac network, & I'd rather not set up AFP on the server unless I have to.... (I can run an AFP share on my (debian) linux box can't I? I should be able to, it seems to do every other type of file share.....)

currently im connected to two shares on my server, the first, my home folder (schiznik) and the second my proposed iTunes share (audio)

This is the output of ls -hla /Volumes/:

ishidourou:/Volumes schiznik$ ls -lha
~~snip~~
drwx------   1 schiznik  admin      16K 27 Jan 03:42 WORKGROUP;ACATHLA
drwx------   1 schiznik  admin      16K 27 Jan 03:46 WORKGROUP;ACATHLA-1
As the numbered shares arent in any order other than the order I mount them, is there any (command line) way I can tell which is which to put into the applescript above?

[ Reply to This | # ]
Would this work with samba shares? YES..
Authored by: schiznik on Jan 27, '05 12:50:24AM
To answer my own question...

When the share is mounted on the desktop, create an alias and move it to somewhere. I used ~/samba/server/MusicShare/

I also went through the 4 comps on my lan making a load of aliases thus making a nice click-to-mount list of shares that turn into directories when mounted :)

[ Reply to This | # ]

iPod as a Fire Wire drive
Authored by: Mucho Grande on Jan 27, '05 08:51:15AM

Would it be possible to use an iPod as your Fire Wire disk?



[ Reply to This | # ]
yes, but not like you'd think.
Authored by: Thom on Jan 28, '05 06:55:43PM

You can use the iPod as a player, AND as a hard drive, but you cannot use the iPod to store your iTunes Music Library (as a hard drive) AND expect those very same files to also be accessible to the iPod.

While I may personally disagree with this approach by Apple, I can understand why they did it. One reason is piracy. They don't want to encourage people to copy music OFF of iPods (eg to give to their friends.) Though methods exist to grab the music from an iPod's (private/internal) music file storage area, none are supported by Apple.

Another reason is probably indexing. If you've ever looked inside the iTunes Music Library folder, you'll see that it contains one folder for each artist, subfolders for each album, and then the music files from those albums. The iPod, on the other hand, stores all of your music files in a single level of folders (F00..F##) stored on the device in a series of hidden folders.

In other words, you can *either* have your music on there for _playback_ from the iPod, OR for _storage_ ON the iPod, but not both. You'd literally have to put it on there twice, once on the 'iPod side' and once on the 'Hard Drive' side.

So even though you COULD do it, it wouldn't make much sense to do it. I may not agree with their choices, but I can see why they did it that way. Better to store your music on an external HD which isn't fighting for space with your iPod music library. :)

(Besides, your iTunes music library should always be bigger than your iPod's capability to hold music, or equal. That, or you need to broaden your musical tastes...)



[ Reply to This | # ]
The advantage of linking
Authored by: natethebobo on Feb 01, '05 10:25:24PM

Hi all, my first post... here goes.

The advantage of linking to separate libraries is the entirely separate listings: if my laptop is not connected to the shared library, I'd like to not have to wade through a screen filled with exclamation points in order to see what music is actually available. In addition, I'm pretty sure the iTunes Music Library file stores the location of the music folder, so there shouldn't be any "Oops, gotta swap back!" moments when the server share (or other external source) is unavailable.

Unfortunately, having separate libraries does mean that the consolidation process is not quite as easy. I suppose you could temporarily change the music folder location, consolidate to the new location, and then swap back, but I don't know if this would incur duplicates on the server.

One could emulate the "no exclamation point" advantage by judicious use of playlists (perhaps a smart playlist?), but that just doesn't seem as natural as simply not having them present at the base level.

Linking to separate libraries also allows for expandability: so far, we're looking at the "one laptop, one external source" scenario. What if (for whatever reason) the scenario involves multiple possible music servers, say one at home and one at work? Three or more music folders is going to require pointing to the correct one each time, not to mention cluttering up the listings something fierce (especially if the tracks are not all named the same way). Using a script such as this allows for automated selection. 'Course, I suppose the script would have to be modified to load the correct preference when multiple source folders are present....


(As an aside, I believe the existing code could be a little more clear if we used

tell app "System Events"
set home_path to the home directory of current user

to figure out where the link should live. This should also allow the script to get the path for any user, even those with home directories elsewhere.)



[ Reply to This | # ]