Search code examples
macosappletapplescriptitunesautomated-deploy

How to get iTunes to play an iPhone playlist automatically when connected to the iPhone


I have a habit of working/studying while listening to music. And since the Mac I am connected to at work doesn't have all the songs I want, I normally listen to the songs via iTunes from the iPhone Playlists option.

For this, everytime I connect my iPhone to the computer, iTunes detects it, then I have to manually goto the 'iPhone' button in the application, and then "On my iPhone", and then select the playlist, and play a song.

Is there anyway of automating this process ? What I'm looking for, is as soon as I connect my iPhone, iTunes should open the playlist inside my iPhone automatically, and start playing a song at random.

I've tried automating it with Automator. But that doesn't seem to be working. There's something wrong I'm doing in AppleScript ::

tell application "iTunes"
    play playlist named "Sasha" of source of type iPhone
end tell

Solution

  • Ha !! I figured it out !! And then I created an applet that would do this for me using AppleScript.

    And then, I published the steps/code for the same on my blog below. Here's the link ::

    Explanation of Code :: How to start playing songs from your iOS device automatically on your Mac

    And the code for the same ::

    tell application "iTunes"
    
        set theCurrentPlaylist to view of front browser window
        set myiPhone to some source whose kind is iPod
        set mainPhonePlaylist to playlist "Sasha" of myiPhone
        set the view of the front browser window to mainPhonePlaylist
        set EQ enabled to true
    
        play playlist named "Sasha" of myiPhone
        set myRandomSong to random number from 1 to count of tracks of (get view of front window)
        play track myRandomSong of mainPhonePlaylist
    
    end tell