DIY
Reveal Multiple Selected Tracks' Files
I occasionally have need to access the files of tracks that may not always be in the same "Album" folder. iTunes has a "Show in Finder" command (Shift-Command-R) for single tracks so to reveal all the files from disparate folders I have to "Show in Finder" each of the tracks, one at a time.
But what if I could open each selected track's file's folder in its own tab in a single Finder window? Like this:
Each tab is the containing folder for the file of each selected track and each file is highlighted. Even if two or more files are in the same folder the folder will get its own tab for each file.
The script follows:
(more…)
Search iTunes Store via Google
Kirk had a tip about using Google to search the iTunes Store in his Macworld column today. Here's a script for that:
try
set searchText to text returned of (display dialog "Search the iTunes Music Store for:" default answer "")
tell application "Finder" to open location "http://www.google.com/search?q=site:itunes.apple.com " & searchText
end try
Launch and enter some search text and click the "OK" button. A new window with Google results will be displayed by your default browser.
Add Files in Reverse, Sort by Date Added
A Correspondent writes that he sorts his Music library playlist by Date Added and meticulously adds each new album's worth of files to iTunes in reverse order—one file at a time—so that an album will appear in order (well, the order established for them in the Finder); older tracks appear sorted lower in the Music library playlist than newer tracks. Get me?
Predictably, Our Correspondent is dismayed by the drudgery of this method and inquires if AppleScript can provide any relief. AppleScript provide relief from drudgery? Ahoy!
tell application "Finder"
set selectedFiles to selection
repeat with i from (length of selectedFiles) to 1 by -1
my addFile(item i of selectedFiles)
delay 1
end repeat
end tell
to addFile(aFile)
tell application "iTunes"
try
add aFile as alias
end try
end tell
end addFile
Save this as a Script Bundle—named whatever you like—to your ~/Library/Scripts/ folder. This will make the script available in the system-wide Scripts menu at the right side of the menu bar. Select the files in the Finder you want to add, which have been sorted in the order you want, and launch the script. It will add the files to iTunes in reverse order so that when they are sorted by Date Added in iTunes they appear in the order you had for them in the Finder.
UPDATE November 11, 2013: Added 1 second delay in repeat loop to prevent tracks from having the same date added (to the second) and sorting arbitrarily.
AirPlay Scripting Workaround
As previously noted, you can't do this without getting -1728 errors:
But you can do this:
tell application "iTunes"
set apDevices to (get a reference to AirPlay devices)
-- see?
log (get name of apDevices)
-- or
repeat with aDevice in apDevices
log (get aDevice's name)
end repeat
-- or
repeat with aDevice in AirPlay devices
log (get aDevice's name)
end repeat
end tell
That's if you need to do that.
Toggle Stereo/Mono Audio Output
Correspondent Simon Crosbie has set up an amp and pair of speakers in his workshop which is connected to an Airport Express. Unfortunately, the speakers are some distance apart, so that he may be near one speaker or another at any time, and will only hear that channel's output. Simon wanted to know if there's a way to toggle between stereo and mono output so he can hear more than just half of a stereo recording.
Yes, there is a way. Go to System Preferences > Accessibility. Choose "Audio" in the left-hand list and in the panel that appears click the checkbox next to "Play stereo audio as mono".
Goodnight everybody!
Wait a minute. I almost forgot I wrote this script to do it:
tell application "System Preferences"
reveal anchor "Hearing" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
tell application process "System Preferences"
set frontmost to true
tell window "Accessibility"
##--> pre 10.9 set monoStereoCheckbox to checkbox 2 of group 1
set monoStereoCheckbox to checkbox "Play stereo audio as mono"
if (get value of monoStereoCheckbox) as boolean is true then
set ddMessage to "Switch to STEREO output?"
else
set ddMessage to "Switch to MONO output?"
end if
if button returned of (display dialog ddMessage buttons {"No", "Yes"} default button 2) is "Yes" then
tell monoStereoCheckbox to click
end if
end tell
end tell
end tell
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
[UPDATE November 13, 2013: The original script has been updated for Mavericks. Note the commented line for pre-10.9 systems and the line that follows it. Set the monoStereoCheckbox variable using one or the other depending on the OS.]
[UPDATE October 17, 2014: Another change for compatibility with Yosemite. The line "set frontmost to true" is inserted right after the first tell application process "System Preferences" line near the beginning.]
I would save this script in the system wide Scripts menu (install it in ~/Library/Scripts/). Because the script uses (gulp) GUI scripting you must make sure that "Enable access for assitive devices" is checked in the Accessibility System Preferences panel.
Smarties among you can figure out how to switch mono/stereo when using AppleScript to change AirPlay speakers.
And bear in mind that while the script works with the current OS (and probably an OS that may be released this Fall), Apple may change the layout of the System Preferences panels in a future update, in which case the GUI scripting will have to be updated.
[UPDATE December 28, 2018: Mojave made some changes and the updated version of the script can be seen here.
Project: Change AirPlay Speakers, Change EQ
I don't fiddle much with iTunes EQ settings. I most frequently send audio to a receiver and, if necessary, tweak the tone settings there. But I realised that if you're using AirPlay, you may want a different EQ setting for a selected AirPlay device. If you don't mind firing a script whenever you want to change AirPlay speakers—and you don't mind doing some of the script-writing yourself—here's a simple way to acomplish that.
And I do mean simple. This script is pretty basic and could be finessed much more thoroughly. It will only allow you to select a single AirPlay device (I don't believe there can be a different EQ for each active AirPlay device simultaneously) but it'll get the job done.
Here's the script. Open it in AppleScript Editor:
tell application "iTunes"
set listOfAirPlayNames to (get name of every AirPlay device)
set chosenAirPlayName to (choose from list listOfAirPlayNames with prompt "Change AirPlay Speakers to:")
if chosenAirPlayName is false then return -- user pressed Cancel
set chosenAirPlayName to (chosenAirPlayName as text) -- coerce to text from list
# This is the part you have to code:
if chosenAirPlayName is "Computer" then set chosenEQName to "Rock"
if chosenAirPlayName is "Apple TV" then set chosenEQName to "My Customized EQ"
if chosenAirPlayName is "Bedroom Airport Express" then set chosenEQName to "Classical"
# and so on...
# apply the changes
set current AirPlay devices to AirPlay device chosenAirPlayName
set current EQ preset to EQ preset chosenEQName
end tell
You will have to supply the names of your AirPlay devices and the name of the EQ setting you want to use with each. The latter is easy, just use the name of an EQ preset as it's displayed in the Equalizer Window. To get the accurate names of the Airplay devices, just run the script from AppleScript Editor and then right away click the "Cancel" button in the choose list dialog. In the AppleScript Editor Event Log window you'll see the names listed. Use these names in each of the repeating lines of code in the script. You may have fewer or more than the three example lines in the original script. Edit accordingly.
When those edits have been made, "Save" the script as "Script" and named whatever you like and saved in your [home]/Library/iTunes/Scripts/ folder. And, like my Mom always says, add a keyboard shortcut to launch it.
Remember: if you manually change your AirPlay speakers in iTunes, without using the script, the EQ will not change. That only happens when you run the script.
So also: smarties can probably figure out how to set a discrete volume for each chosen device using the Airplay device sound volume property.
UPDATE: Just to be clear, it is the main iTunes EQ setting that is changed, not the EQ setting for individual tracks.
More Airplay stuff
Earlier, I posted a way to hardcode the Airplay devices in a script. But if you only have one computer, AirPort Express, or Apple TV kind of Airplay device you can forego using the name property and do something like this, which sets my lone Apple TV as the current Airplay device:
tell application "iTunes"
set current AirPlay devices to (get AirPlay devices whose kind is Apple TV)
end tell
Even though there is only a single item result from Airplay devices whose kind is Apple TV, it's returned as a list which is what current AirPlay devices takes.
The other kind values, AirPlay device and unknown, are too generic to use this way—unless you know you only have one of them.
Hardcode Airplay Device Speakers
Correspondent Matt Stevens sent the following, which illustrates how to hard code your Airplay device names:
tell application "iTunes"
set computerSpeaker to (first AirPlay device whose name = "Computer")
set kitchenSpeaker to (first AirPlay device whose name = "Kitchen")
set current AirPlay devices to {computerSpeaker, kitchenSpeaker}
end tell
The current AirPlay devices application property accepts a list—even if the list is only one item.