{"id":2269,"date":"2009-01-03T18:53:53","date_gmt":"2009-01-04T00:53:53","guid":{"rendered":"http:\/\/granades.com\/?p=2269"},"modified":"2009-01-03T18:53:53","modified_gmt":"2009-01-04T00:53:53","slug":"converting-itunes-playlists-to-m3u-playlists-on-a-mac","status":"publish","type":"post","link":"https:\/\/granades.com\/?p=2269","title":{"rendered":"Converting iTunes Playlists to M3U Playlists on a Mac"},"content":{"rendered":"<p>So I wasn&#8217;t content with just <a href=\"https:\/\/granades.com\/wordpress\/2009\/01\/02\/converting-itunes-playlists-to-m3u-playlists\/\">one way<\/a> of creating M3U playlists out of iTunes. I went and wrote another. There&#8217;s more than one way to do it, as I learned writing Perl programs.<\/p>\n<p>Pity I&#8217;m writing in Python.<\/p>\n<p>Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses <a href=\"http:\/\/appscript.sourceforge.net\/\">appscript<\/a>, an event bridge that lets you do what Applescript does, only in a real language like Python. It&#8217;s called <a href=\"https:\/\/granades.com\/wordpress\/downloads\/iTunesm3u.py\">iTunesm3u.py<\/a>, and requires that you <a href=\"http:\/\/appscript.sourceforge.net\/py-appscript\/install.html\">install py-appscript<\/a> first. To use it, have iTunes open. Select a playlist. Then run the script (or double-click the script if you turn it into an app with <a href=\"http:\/\/svn.pythonmac.org\/py2app\/py2app\/trunk\/doc\/index.html\">py2app<\/a>) and it&#8217;ll create an .m3u file in the same directory as the script.<\/p>\n<pre><code>\r\n#!\/usr\/bin\/env python\r\n\r\n# Using the appscript Python-to-applescript bridge, convert an iTunes\r\n# playlist into m3u format.\r\n#\r\n# Author: Stephen Granade\r\n# Date: 2 January 2009\r\n\r\nimport math, re, sys, os\r\nfrom appscript import *\r\n\r\n# Search-and-replace strings to adjust the mp3's locations if necessary.\r\nsandrStrs = { \"\/Volumes\": \"smb:\/\/sargent\" }\r\n\r\n# For more information about what classes etc. are available from iTunes\r\n# via appscript, see\r\n# http:\/\/appscript.sourceforge.net\/objc-appscript\/iTunes-objc\/index.html\r\n\r\n# Get ahold of iTunes\r\niTunes = app('iTunes')\r\n\r\n# The browser window's view is the currently-selected playlist\r\ntry:\r\n    playlist=iTunes.browser_windows[1].view()\r\nexcept CommandError, detail:\r\n    if detail.errornumber == -1731:\r\n        print \"There is no current playlist.\"\r\n        sys.stdout.write('\\a')\r\n        sys.stdout.flush()\r\n        sys.exit()\r\n    else:\r\n        raise CommandError, detail\r\n\r\n# Use the playlist's name as that of the m3u file\r\noutfn = os.path.abspath(__file__)\r\noutfn = os.path.join(os.path.dirname(outfn),playlist.name()+\".m3u\")\r\n\r\noutf = open(outfn, \"w\")\r\n\r\noutf.write(\"#EXTM3U\\n\")\r\n\r\nfor track in playlist.tracks():\r\n    # Skip any files whose locations aren't currently available\r\n    # If the file doesn't exist on disk, then trying to access the\r\n    # location will throw an AttributeError exception.\r\n    try:\r\n        fileloc = track.location().path\r\n        if not os.path.isfile(fileloc):\r\n            throw(AttributeError)\r\n        # Perform search-and-replace on the file location\r\n        for old, new in sandrStrs.iteritems():\r\n            fileloc = fileloc.replace(old, new)\r\n        durstr = \"%d\" % math.floor(track.duration())\r\n        outf.write(\"#EXTINF:\"+durstr+\",\"+track.name()+\"\\n\")\r\n        outf.write(fileloc+\"\\n\")\r\n    except AttributeError:\r\n        print \"\\\"\"+track.name()+\"\\\" isn't available on disk. Skipping.\"\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So I wasn&#8217;t content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There&#8217;s more than one way to do it, as I learned writing Perl programs. Pity I&#8217;m writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript, &hellip; <a href=\"https:\/\/granades.com\/?p=2269\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Converting iTunes Playlists to M3U Playlists on a Mac<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2269","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"So I wasn&#039;t content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There&#039;s more than one way to do it, as I learned writing Perl programs. Pity I&#039;m writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/granades.com\/?p=2269\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Live Granades - Just another WordPress site\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades\" \/>\n\t\t<meta property=\"og:description\" content=\"So I wasn&#039;t content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There&#039;s more than one way to do it, as I learned writing Perl programs. Pity I&#039;m writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/granades.com\/?p=2269\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2009-01-04T00:53:53+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2009-01-04T00:53:53+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades\" \/>\n\t\t<meta name=\"twitter:description\" content=\"So I wasn&#039;t content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There&#039;s more than one way to do it, as I learned writing Perl programs. Pity I&#039;m writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#blogposting\",\"name\":\"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades\",\"headline\":\"Converting iTunes Playlists to M3U Playlists on a Mac\",\"author\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\"},\"datePublished\":\"2009-01-03T18:53:53+00:00\",\"dateModified\":\"2009-01-03T18:53:53+00:00\",\"inLanguage\":\"en-US\",\"commentCount\":3,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#webpage\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/granades.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#listItem\",\"name\":\"Converting iTunes Playlists to M3U Playlists on a Mac\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#listItem\",\"position\":2,\"name\":\"Converting iTunes Playlists to M3U Playlists on a Mac\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/granades.com#listItem\",\"name\":\"Home\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\",\"name\":\"Live Granades\",\"description\":\"Just another WordPress site\",\"url\":\"https:\\\/\\\/granades.com\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\",\"url\":\"https:\\\/\\\/granades.com\\\/?author=3\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#webpage\",\"url\":\"https:\\\/\\\/granades.com\\\/?p=2269\",\"name\":\"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades\",\"description\":\"So I wasn't content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There's more than one way to do it, as I learned writing Perl programs. Pity I'm writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?p=2269#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/granades.com\\\/?author=3#author\"},\"datePublished\":\"2009-01-03T18:53:53+00:00\",\"dateModified\":\"2009-01-03T18:53:53+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/granades.com\\\/#website\",\"url\":\"https:\\\/\\\/granades.com\\\/\",\"name\":\"Live Granades\",\"description\":\"Just another WordPress site\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/granades.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades","description":"So I wasn't content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There's more than one way to do it, as I learned writing Perl programs. Pity I'm writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,","canonical_url":"https:\/\/granades.com\/?p=2269","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/granades.com\/?p=2269#blogposting","name":"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades","headline":"Converting iTunes Playlists to M3U Playlists on a Mac","author":{"@id":"https:\/\/granades.com\/?author=3#author"},"publisher":{"@id":"https:\/\/granades.com\/#organization"},"datePublished":"2009-01-03T18:53:53+00:00","dateModified":"2009-01-03T18:53:53+00:00","inLanguage":"en-US","commentCount":3,"mainEntityOfPage":{"@id":"https:\/\/granades.com\/?p=2269#webpage"},"isPartOf":{"@id":"https:\/\/granades.com\/?p=2269#webpage"}},{"@type":"BreadcrumbList","@id":"https:\/\/granades.com\/?p=2269#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/granades.com#listItem","position":1,"name":"Home","item":"https:\/\/granades.com","nextItem":{"@type":"ListItem","@id":"https:\/\/granades.com\/?p=2269#listItem","name":"Converting iTunes Playlists to M3U Playlists on a Mac"}},{"@type":"ListItem","@id":"https:\/\/granades.com\/?p=2269#listItem","position":2,"name":"Converting iTunes Playlists to M3U Playlists on a Mac","previousItem":{"@type":"ListItem","@id":"https:\/\/granades.com#listItem","name":"Home"}}]},{"@type":"Organization","@id":"https:\/\/granades.com\/#organization","name":"Live Granades","description":"Just another WordPress site","url":"https:\/\/granades.com\/"},{"@type":"Person","@id":"https:\/\/granades.com\/?author=3#author","url":"https:\/\/granades.com\/?author=3"},{"@type":"WebPage","@id":"https:\/\/granades.com\/?p=2269#webpage","url":"https:\/\/granades.com\/?p=2269","name":"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades","description":"So I wasn't content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There's more than one way to do it, as I learned writing Perl programs. Pity I'm writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/granades.com\/#website"},"breadcrumb":{"@id":"https:\/\/granades.com\/?p=2269#breadcrumblist"},"author":{"@id":"https:\/\/granades.com\/?author=3#author"},"creator":{"@id":"https:\/\/granades.com\/?author=3#author"},"datePublished":"2009-01-03T18:53:53+00:00","dateModified":"2009-01-03T18:53:53+00:00"},{"@type":"WebSite","@id":"https:\/\/granades.com\/#website","url":"https:\/\/granades.com\/","name":"Live Granades","description":"Just another WordPress site","inLanguage":"en-US","publisher":{"@id":"https:\/\/granades.com\/#organization"}}]},"og:locale":"en_US","og:site_name":"Live Granades - Just another WordPress site","og:type":"article","og:title":"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades","og:description":"So I wasn't content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There's more than one way to do it, as I learned writing Perl programs. Pity I'm writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,","og:url":"https:\/\/granades.com\/?p=2269","article:published_time":"2009-01-04T00:53:53+00:00","article:modified_time":"2009-01-04T00:53:53+00:00","twitter:card":"summary","twitter:title":"Converting iTunes Playlists to M3U Playlists on a Mac - Live Granades","twitter:description":"So I wasn't content with just one way of creating M3U playlists out of iTunes. I went and wrote another. There's more than one way to do it, as I learned writing Perl programs. Pity I'm writing in Python. Anyway, this method only works on a Mac, because it uses Applescript. Actually, it uses appscript,"},"aioseo_meta_data":{"post_id":"2269","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-06-26 00:23:19","updated":"2025-11-03 06:17:17","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/granades.com\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tConverting iTunes Playlists to M3U Playlists on a Mac\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/granades.com"},{"label":"Converting iTunes Playlists to M3U Playlists on a Mac","link":"https:\/\/granades.com\/?p=2269"}],"_links":{"self":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2269"}],"version-history":[{"count":3,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2269\/revisions"}],"predecessor-version":[{"id":2272,"href":"https:\/\/granades.com\/index.php?rest_route=\/wp\/v2\/posts\/2269\/revisions\/2272"}],"wp:attachment":[{"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/granades.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}