dougscripts.com

DIY

March 16 2014 - 12:18 pm

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…)

March 6 2014 - 1:33 pm

iTunes Store Power Search at Your Fingertips

Kirk McElhearn posted today about accessing the (kinda hidden) iTunes Store "Power Search" panel:

The trick to making this panel visible is to use this link, which I suppose you could bookmark in your web browser and Command-Tab to that whenever you wanted to power search. But in the last century human beings invented AppleScript to free themselves from time-consuming drudgeries like that.

Just enter this in AppleScript Editor (or click the little script icon to open it automatically):

tell application "iTunes"

open location "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch"

end tell

Name it whatever you like and Save it with the Format of "Script" in your ~Library/iTunes/Scripts/ folder. Then assign it a shortcut in iTunes.

This post was updated on March 9, 2014.

Also see this post: More iTunes Store Power Search at Your Fingertips.

February 2 2014 - 8:17 am

Disc 1 of 1

A Corespondent laments:

My personal preference when dealing with the disc count field (1 of 2, etc) is to leave it blank for single CD albums instead of tagging them as "1 of 1." There is something about 1 of 1 that just bugs me so I try to clear those out. Can you think of anything you have that can search in those fields? Sorting the library by disc number [is an unsatisfactory solution] because every disc 1—regardless if there is a second disc—gets sorted.

Yeah. It would be easy to do a Multi-Item edit on these guys if you could only corral 'em all together somehow. But: sorting by Disc # sorts by Disc Number alone and ignores the Disc Count so the "1 of 1" tracks are not necessarily sorted together; rather, they're sorted by Album (all the Disc 1 albums A-Z, followed by all the Disc 2 albums A-Z, and so on). Smart Playlists are of little use to gather up these tracks since Disc Count is not a smart criterion.

So here's a script that will look at each track in a selection or all the tracks in the selected playlist; if the track's Disc Count is 1 the script will set it to 0, effectively blanking it:

tell application id "com.apple.iTunes"

set thePlaylist to (get view of front window)

set sel to selection

if sel is {} then

# all tracks in playlist

repeat with i from 1 to (get index of last track of thePlaylist)

my processTheTrack(track i of thePlaylist)

end repeat

else

# selected tracks

repeat with i from 1 to (length of sel)

my processTheTrack(item i of sel)

end repeat

end if

end tell

to processTheTrack(t)

tell application id "com.apple.iTunes"

try

if disc count of t is 1 then set disc count of t to 0

end try

end tell

end processTheTrack

You can save that in AppleScript Editor named whatever you like and using "Script" as the file format to your ~/Library/iTunes/Scripts/ folder whereupon it will appear in the iTunes Scripts menu.

The script iterates through each track individually, so if you run it against your entire Music library playlist you'll have time to file nails, tidy bookshelves, re-string guitar, or perform some other menial task.

UPDATE: To eliminate the disc number as well (although I prefer to keep it) change the handler to this:

to processTheTrack(t)

tell application id "com.apple.iTunes"

try

if disc count of t is 1 then

set disc number of t to 0

set disc count of t to 0

end if

end try

end tell

end processTheTrack

December 13 2013 - 1:10 pm

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.

November 6 2013 - 8:18 am

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.

October 17 2013 - 7:07 pm

AirPlay Scripting Workaround

As previously noted, you can't do this without getting -1728 errors:

tell application "iTunes"

set apDevices to (get AirPlay devices)

end tell

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.

August 16 2013 - 9:34 am

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.

May 30 2013 - 2:14 pm

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.

May 17 2013 - 12:33 pm

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.

May 16 2013 - 5:22 pm

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.

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.