Tips: Delaying the start of iTunes to avoid the missing library error on macOS

Posted:
in iPod + iTunes + AppleTV edited February 2017
If you're running a machine with external drives, it's possible that they won't be mounted when iTunes starts looking for data. AppleInsider explains how to get around this, with a simple AppleScript.




While iTunes and Photos data is generally stored on the system drive, users with especially large libraries can move them to external drives, or network shares to save limited space. Given how the macOS works, and the relative slowness of external media, an app that can't find its data complains, and asks to re-locate the library.

A very simple script, coupled with proper system configuration can be used in place of manually launching iTunes after the entire boot cycle is complete. Here's how to do it.

Configure the system to not bypass your hard work

  • Select "restart."
  • Before the 60-second timer expires, uncheck "reopen windows when logging back in."

Remove external drive-dependent apps from starting by themselves at launch

  • Open "System Preferences" and open "Users and Groups"
  • Remove apps that are giving you grief about missing data by selecting them, and hitting the - button

Write the script

  • In the Utilities folder, open "Script Editor"
  • In the AppleScript window, type:
Delay 10
Tell application "iTunes" to launch
Other applications can be added to the list, in the same syntax as "iTunes" above.

Make the AppleScript applet, and make it launch on start

  • Still in the Script Editor, select Export from the File menu
  • Change "File Format" to "Application" and hit save
  • Re-open "Users and Groups"
  • Add the applet you just made to your list of startup items, by hitting + and navigating to where you saved the applet.


Reboot to test.

What to do if it doesn't work

Some drives spin up faster than others. The "Delay 10" line in the script works with all the external enclosures and drives we've tested it with, but adding a few more seconds may be necessary, depending on your hardware.
Soliwatto_cobra
«1

Comments

  • Reply 1 of 32
    SoliSoli Posts: 10,035member
    1) Thanks, Mike Wuerthele, I run into this issue on most restarts. The funny thing is I have a lot of scripts to automate many functions and never considered this simple one.

    2) May I suggest also including an Automator-based option?



    3) It's beyond my ken, but it's possible to only have the app(s) run only after the drive (or network share) has been mounted, which could save a couple seconds. Even more complex, you could have it send you a notification—assuming this is a headless Mac, like in my case—if the drive isn't mounted, which means the app(s) then don't launch.

    I'm not sure if the following would work via Automator, but here's an example:


    Here's a link to an Apple Script for mounting an external drive:

    edited February 2017 watto_cobrapscooter63argonaut
  • Reply 2 of 32
    hexclockhexclock Posts: 1,254member
    I can imagine using this on a Logic rig that uses external drives for samples and instruments. 
    watto_cobraargonaut
  • Reply 3 of 32
    Mike WuertheleMike Wuerthele Posts: 6,861administrator
    hexclock said:
    I can imagine using this on a Logic rig that uses external drives for samples and instruments. 
    Yup. Just have to add 

    "Tell application Logic Pro X to launch"

    In place of, before, or after the iTunes line.
    watto_cobraargonaut
  • Reply 4 of 32
    Mike WuertheleMike Wuerthele Posts: 6,861administrator
    Yup, you can get there that way too! 

    My home server gets crabby from time to time, is also headless, and it shuts down daily at 6AM, and reboots at 6:10. This prevents me from having to ARD or Screen Sharing into it to load the iTunes library.
    Soli said:
    1) Thanks, Mike Wuerthele, I run into this issue on most restarts. The funny thing is I have a lot of scripts to automate many functions and never considered this simple one.

    2) May I suggest also including an Automator-based option?
    edited February 2017
  • Reply 5 of 32
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
  • Reply 6 of 32
    SoliSoli Posts: 10,035member
    My home server gets crabby from time to time, is also headless, and it shuts down daily at 6AM, and reboots at 6:10. This prevents me from having to ARD or Screen Sharing into it to load the iTunes library.
    Are you sure you don't have this (or one of the other possible time-based settings enabled?


  • Reply 7 of 32
    hexclockhexclock Posts: 1,254member
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    StrangeDayswatto_cobra
  • Reply 8 of 32
    StrangeDaysStrangeDays Posts: 12,879member
    No, we must blame apple for this because the echo chamber blogger narrative says they're no longer any good at software. 
    Soliwatto_cobrachiaargonaut
  • Reply 9 of 32
    SoliSoli Posts: 10,035member
    hexclock said:
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    Definitely not a "bug" but it's certainly something that could be submitted to Apple so that when the iTunes Library is being pulied from an external drive or a network share, it will automatically wait for that drive to be mounted before iTunes looks for the iTunes Library files since the app will know the path is so something external. If after x-seconds that drive or share is never mounted it should then pop up a message about being able to not find the iTunes Library.

    Maybe I'll submit a request next week, but this would be such a low priority that I'm skeptical that they'd ever add it.
    edited February 2017
  • Reply 10 of 32
    hexclock said:
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    Right. Of course. That would be impossible to fix in software such as adding a notification for when a new drive comes online.
  • Reply 11 of 32
    What is this? A frickin' Windows tutorial for nerds?
  • Reply 12 of 32
    Anyone have any idea why I get this from Scrip Editor?

    Script is exact copy of one posted:

    delay 10

    tell application iTunes to launch


    Result

    error "The variable iTunes is not defined." number -2753 from "iTunes"

  • Reply 13 of 32
    hexclockhexclock Posts: 1,254member
    macbisho said:
    Anyone have any idea why I get this from Scrip Editor?

    Script is exact copy of one posted:

    delay 10

    tell application iTunes to launch


    Result

    error "The variable iTunes is not defined." number -2753 from "iTunes"

    try putting iTunes in quotes
  • Reply 14 of 32
    Mike WuertheleMike Wuerthele Posts: 6,861administrator
    Soli said:
    My home server gets crabby from time to time, is also headless, and it shuts down daily at 6AM, and reboots at 6:10. This prevents me from having to ARD or Screen Sharing into it to load the iTunes library.
    Are you sure you don't have this (or one of the other possible time-based settings enabled?


    It is an intentional reboot, so yes :D
  • Reply 15 of 32
    SoliSoli Posts: 10,035member
    Soli said:
    My home server gets crabby from time to time, is also headless, and it shuts down daily at 6AM, and reboots at 6:10. This prevents me from having to ARD or Screen Sharing into it to load the iTunes library.
    Are you sure you don't have this (or one of the other possible time-based settings enabled?


    It is an intentional reboot, so yes :D
    Do you have a solution for enabling FileVault on your boot drive while also allowing automatic login to work while being able to lock the account?

    FileVault was originally only on the user accounts, but when they moved to full-disk encryption for FV2 it does two things I don't like. One, it shows the usernames on the pre-boot screen to unlock the volume when I'd prefer having both the username and password blank as an additional form of protection. Two, it doesn't let me use screen sharing into the device until the full OS is loaded, which doesn't seem to be an option with FV2 enabled.

    I'd also like for Apple to have a way to load an account in the background while the account is locked. I call this "secure automatic login." The best workaround that I've found is a script that will auto-enable a screensaver which also locks the account as the first start up action. This, however, is insecure as one could disable startup scripts and launch agents during a reboot.

    I already keep as little as possible on my headless Mac mini's boot disk because I need it to boot into the OS without having to physically access that account to login to get it running, but there's still plenty of personal, unencrypted data on that boot drive because of how macOS is deigned.

    I could use the Advanced Option for the user account to change its path to the external drive so that full disk encryption on my external drive would be in play, but that would also mean creating an limited access user account that would automatically login and then I'd have to load the external drive and then switch user accounts, and then logout of the limited access account so it's not using any resources. This could be automated but it's still a lot of rigmarole for something I was was a built-in option, and feels too un-Appley to me.


    Am I missing something simple that's already designed to do what I want?


    tl;dr; I'd like Full Disk Encryption that will automatically login to a locked account without having the account unlocked until the user manually inputs the username and password to access the desktop.
  • Reply 16 of 32
    StrangeDaysStrangeDays Posts: 12,879member
    grangerfx said:
    hexclock said:
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    Right. Of course. That would be impossible to fix in software such as adding a notification for when a new drive comes online.
    And perhaps they will. Software receives enhancements all the time. Do you believe the current versions of all your software fell off the tree this way, fully-formed? Or do you believe they got better over time as people fixed issues and added enhancements?

    For what it's worth, I use an external drive and have never had this problem (evidently my external drive is fast).
    edited February 2017
  • Reply 17 of 32
    Mike WuertheleMike Wuerthele Posts: 6,861administrator
    grangerfx said:
    hexclock said:
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    Right. Of course. That would be impossible to fix in software such as adding a notification for when a new drive comes online.
    And perhaps they will. Software receives enhancements all the time. Do you believe the current versions of all your software fell off the tree this way, fully-formed? Or do you believe they got better over time as people fixed issues and added enhancements?

    For what it's worth, I use an external drive and have never had this problem (evidently my external drive is fast).
    It's primarily an issue when the boot drive is a SSD, and the external is not. It also greatly depends on the enclosure's bridgeboard.
    edited February 2017
  • Reply 18 of 32
    zzyzyzzyzy Posts: 1unconfirmed, member
    Quotes are needed around iTunes: tell application "iTunes" to launch
  • Reply 19 of 32
    MarvinMarvin Posts: 15,324moderator
    Soli said:
    hexclock said:
    grangerfx said:
    I guess having Apple fix the bug in iTunes is an unthinkable solution. If you put all the iTunes bug reports end to end, they would reach from here to Jupiter. They just close the ones I file without explanation most of the time or with some stupid impractical excuse.
    It isn't a bug in iTunes. It's that the OS boots up (presumably off an SSD) and loads the start-up items faster than the external platters can spin up. 
    Definitely not a "bug" but it's certainly something that could be submitted to Apple so that when the iTunes Library is being pulied from an external drive or a network share, it will automatically wait for that drive to be mounted before iTunes looks for the iTunes Library files since the app will know the path is so something external. If after x-seconds that drive or share is never mounted it should then pop up a message about being able to not find the iTunes Library.
    Another way to have music externally is to keep the library on the main drive and just relocate the music. Then you change the iTunes Media folder location in iTunes Preferences > Advanced > iTunes Media folder location. If the drive isn't mounted, it still opens iTunes ok with all the tracks, the music just won't play until the drive is connected. Another way is to relocate the music and add it to iTunes without copying it to the music folder. That lets you have multiple locations with a single library but it means renaming drives can cause problems.

    iTunes should really be able to accommodate multiple music locations or libraries simultaneously so that there could be a local audio store, an external and a network share at the same time. On adding music, it would be dragged into the appropriate location. This applies to all their apps like Photos having multiple libraries and families can have a shared library as well as each person having a personal one. They'd still need the feature to wait on each being available but wouldn't have to hold up the app from loading.
  • Reply 20 of 32
    zzyzy said:
    Quotes are needed around iTunes: tell application "iTunes" to launch
    I wondered about that when I read the article.  So 

    Write the script

    • In the Utilities folder, open "Script Editor"
    • In the AppleScript window, type:
    Delay 10
    Tell application iTunes to launch

    should be updated to include the quotes around iTunes?

    BTW, I appreciate articles like this.  I've been a Mac user since the beginning, and I forget that AppleScript is still an option.
    Soli
Sign In or Register to comment.