dougscripts.com

Controlling iTunes

December 1 2018 - 7:44 pm

Shortcuts and SSHing to Snow Leopard

Like you-wouldn't-believe-how-many other people, I still run an old Mac Mini with Snow Leopard on it. It's been pretty reliable as an occasional music server and we still use it to play iTunes internet radio on AirPlay devices around the house. It also manages some backup tasks on my network. It runs headless and I access it through Screen Sharing when necessary.

It is more difficult then it used to be to remotely control Snow Leopard with AppleScript from newer operating systems. At one time, you could just address the machine and run commands with a username and password. Now you need to set up SSH. I haven't done that and just use Screen Sharing.

But, believe it or not, the Run Script Over SSH action I described earlier works with Snow Leopard out-of-the-box. I will now set about creating a batch of Shortcuts to be able to quickly manage stuff on the Mac Mini with AppleScript, like playing a parrticular radio station in iTunes, shutting music down, changing AirPlay devices and so on, which I can call from my iPhone. Pretty cool.

December 1 2018 - 11:54 am

Scripting to a Mac with iOS Shortcuts

I'm not particularly bowled over by Shortcuts on iOS. I just don't use my iPhone and iPads rigorously enough that I'm inspired to automate many tasks. But I get that it's a thing.

What I find very interesting however is that you can use Shortcuts to launch AppleScripts on a targeted Mac. So, while the "Music" actions on iOS are somewhat limited, there's actually some potential usefulness in calling scripts (via Siri, even) from your iOS device to control iTunes on a Mac.

A nice basic tutorial by the great folks at Late Night Software explains how set this up. Essentially, you use the Run Script over SSH action to enter an osascript command to launch a script on a specified Mac. If you've ever done anything with launchd then you will recognize some similarities.

There are some limitations. First, AppleScript does not run on iOS. So anything you want to do with this technique will necessarily be on one particular Mac. (While I can imagine that it is possible to run other SSH commands from that Mac to other Macs, making all of that swing is beyond the scope of this article.)

Second, I am working strictly with scripting iTunes on a Mac. Many other apps on your Mac can be controlled with AppleScript, too.

Third, there is limited opportunity for user-interaction and feedback. (Depending on the use case, it is possible to manage some simple back-and-forth user-interaction in Shortcuts. But, again: beyond, scope, article.)

So, considering those parameters, there aren't many iTunes track and playlist management things I'd want to do remotely; I'd prefer to be operating on track info while sitting in front of iTunes. But we can still use Shortcuts to perform some serviceable tasks with iTunes remotely, things that can't be done conveniently with the Remote app on iOS.

Below, I describe how to create some Shortcuts that can launch scripts on your Mac. One will save the currently playing track to a "Favorites" playlist, another to change the AirPlay configuration and, lastly, one that pauses iTunes for five minutes. These may give you ideas for your own Shortcuts.

(more…)

April 23 2018 - 11:55 am

NEW: Side Splitter

Back in the day, LP record albums were experienced as pairs of "sides", right?

A decent record side was about 22 to 27 minutes long. And so we got used to listening to chunks of music of this duration. These time constraints on a record would often affect how the album was programmed, such as the song order and perhaps other conceptual factors.

If you spent a lot of time listening to record albums this way, you may remember the convention of "flipping the record" after the first side was finished in order to hear the other side. It only took a few moments to do so, but this pause in the action is the sort of thing you don't experience much with CDs and virtually never with hours-long playlists.

I wondered what it would be like now to experience some of my classic digitized albums with a deliberate pause between the last song of one side and the first song of the next side. So, here's Side Splitter.

It will copy a selection of tracks into separate user-designated "album side" playlists (by placing a checkmark next to the last song of a "side") and then offer to auto-play them; when a "side" playlist stops, the script will offer to play the next "side" playlist, which you acknowledge by clicking an "OK" button the script shows in a dialog. When the entire album has played this way, the script will offer to delete the playlists.

It actually brings back that feeling of playing individual record sides.

Side Splitter is free to use with a donation nag. More info and download is on this page.

February 24 2018 - 10:37 am

A Space Between Video Demo

A Space Between will play each track in the selected playlist and will wait (one might say insert but that's technically incorrect) a user-set number of seconds between each. Play can commence at the "top" of the playlist or from a selected track.

NOTE: This script will only work as described when the "Up Next" queue is empty. You can use the "Clear" button" in "Up Next" to empty it of tracks. This is an issue with iTunes 12.2 and later.

May 12 2016 - 4:29 pm

UPDATED: Needle Drop v5.2

Needle Drop is an applet that plays each track in the selected iTunes playlist for a set time interval optionally starting at a set number of seconds into each track, beginning with the selected track.

This latest version adds the "Start fade at seconds" option, which is the number of seconds from the end of the full duration to start fading iTunes' volume for each track. Using the settings above, each track in a playlist would: 1) play for :30 seconds 2) starting at the :10 second mark, 3) begin fading at :24 seconds (30 - 6) and then 4) wait :03 before the next track begins.

Needle Drop is free (donation requested) and more details and download are on this page.

February 17 2016 - 7:24 am

Name New Playlist From Selection

(This a repost from October 25, 2011. The previous post reminded me of it.)

I use the iTunes File > New > Playlist from Selection command a lot to create temporary playlists. Actually, I use the Shift-Command-N shortcut more often than clicking the command in the File menu. But I'm irritated at all the dancing I have to do to name the new "untitled playlist". It takes my attention away from what I was intending to do with the tracks. So, I rigged the script below to the keyboard shortcut Shift-Command-N—and, luckily, it works. Sometimes assigning a shortcut that iTunes is already using doesn't override the original command. The script does exactly what "Playlist from Selection" does except now I can enter the name for the playlist before it's created.

Here's the script:

tell application id "com.apple.iTunes"

try

set sel to selection

set theSource to container of view of front browser window

if sel is {} then error

set opt to (display dialog ¬

"Make new playlist from selected tracks named:" default answer ¬

"" with title "Name New Playlist From Selection" with icon 1)

set newName to (text returned of opt)

if newName is "" then error

on error

return

end try

set newPlaylist to (make new playlist at theSource with properties {name:newName})

repeat with t in sel

try

duplicate t to newPlaylist

end try

end repeat

reveal newPlaylist

end tell

I named it "Name New Playlist from Selection", saved it to ~/Library/iTunes/Scripts/ and gave it the shortcut using these instructions.

October 21 2015 - 1:21 pm

UPDATED: Now Where Was I? v2.0

Forgot to post about this a few days ago when I actually updated the script.

Now Where Was I? v2.0 is a simple applet that, when run while a track is playing or paused, will "remember" the current track and quit iTunes; when it is next run it will launch iTunes and play that track. If a track is set to "Remember playback position", it will pick up playing from where it left off.

This latest version is generally updated for newer versions of iTunes and the Mac OS. More info and download is here.

June 17 2015 - 6:54 am

Script of the Day: A Space Between

A Space Between will play each track in the selected playlist and will wait (one might say insert but that's technically incorrect) a user-set number of seconds between each.

A few extra seconds between tracks can provide a nice bit of atmosphere.

More information and download is on this page.

Previous Scripts of the Day. Subscribe to my RSS feed or follow @dougscripts on Twitter to get daily "Script of the Day" notifications.

June 9 2015 - 7:22 am

Script of the Day: Quick Convert

Quick Convert will convert all or just the selected tracks of the selected Playlist using your choice of available iTunes encoders, restoring your Preferences-set encoder afterwards.

Quick Convert

Additionally, you can:

  • Choose to delete and/or Trash the original tracks and/or files
  • Copy all converted/imported tracks to a new playlist
  • Optionally save AAC encoded tracks as M4B "bookmarkable" and re-add the converted files to the Audiobooks (Books) library

More information and download is on this page.

Previous Scripts of the Day. Subscribe to my RSS feed or follow @dougscripts on Twitter to get daily "Script of the Day" notifications.

May 22 2015 - 6:42 am

Script of the Day: Play Random Album

Play Random Album will quickly scan your library, create a playlist of a complete single album choosen at random and begin playback of the playlist created. Works great when assigned a keyboard shortcut. This is one of my favorite scripts.

More info and download is on this page.

Previous Scripts of the Day. Subscribe to my RSS feed or follow @dougscripts on Twitter to get daily "Script of the Day" notifications.

Site contents © 2001 - 2024 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.