dougscripts.com

Use AppleScript to Open iTunes Tracks in Other Non-Scriptable Applications

Correspondent Adam Price wanted to have an AppleScript open the selected iTunes tracks in an application called Amazing Slow Downer, an app that slows down MP3, AIFF, AAC/MP4 and WAV files without altering their pitch (for transcription purposes, for example).

Amazing Slow Downer is not 'scriptable, but often you can get around this by having the Finder open a file using the desired application. The syntax is usually something like this:

tell application "Finder"
	open file some_file using application "some_application"
end tell

Adam originally tried this, which is also what I would have done ("Amazing X" is the target application):

tell application "iTunes"
	activate
	copy selection to sel
	set i_max to the count of sel
	repeat with i from 1 to i_max
		set track_i to item i of sel
		copy (get track_i's location) to trackpath
		
		tell application "Finder"
			open (trackpath as alias) using application "Amazing X"
		end tell
		
	end repeat
end tell

Surprisingly, this always generated an error: "Handler can't handle objects of this class." Huh?

Well, it took a little brain juice and Googling, but we finally got this to work (note the "using terms from" block):

tell application "iTunes"
	activate
	copy selection to sel
	set i_max to the count of sel
	repeat with i from 1 to i_max
		set track_i to item i of sel
		copy (get track_i's location) to trackpath
		
		using terms from application "Finder"
			tell application "Amazing X"
				open (trackpath as alias)
			end tell
		end using terms from
		
	end repeat
end tell

Success!

I had seen the "using terms from" syntax used when communicating with a remote machine's Finder, but never used like this. Anyway, this snippet worked for me on every non-scriptable MP3-supporting app I have. My own particular bugaboo in this regard is the great Amadeus II Audio Editor, but I've got it going now! Cool!

The only other thing I can suggest is to use "try" blocks to avoid errors if your selection contains tracks which don't have local files (or are missing) and also inside the "open using terms from" block to avoid errors if the app can't open a file.

Site contents © 2001 - 2019 (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 interrupt the one doing it.