–this script works:
tell application “iTunes”
set my_file to alias “Macintosh HD:test.mp3”
open my_file
end tell
– this one works too:
tell application “Finder”
set my_file to alias “Macintosh HD:test.mp3”
open my_file
end tell
– this one also works just fine:
tell application “Finder”
set my_text to “Macintosh HD:test.mp3”
set my_file to alias my_text
open my_file
end tell
– but this script fails:
tell application “iTunes”
set my_text to “Macintosh HD:test.mp3”
set my_file to alias my_text
open my_file
end tell
This is the error that appears:
AppleScript Error, iTunes got an error: Can’t get alias “Macintosh HD:test.mp3”.
What I’m actually trying to do is send mp3 metadata from FileMaker to iTunes. But I’ve reduced the issue to this simple example. First I thought FileMaker was the problem, but then I realized the problem is on the iTunes end. Also, it turns out that I can work around the problem by using what FM calls a calculated Applescript. But that solution is a hack, so I want to avoid it.
The problem is very strange, and driving me nuts. I hope someone can help. Thanks!
iTunes knows indeed the open command of the Standard Suite, but it’s actually not used in iTunes.
Either you want to add a file to the library, then use the add command,
or you want to access an existing track, then reference it directly and change its property values
Stefan: “iTunes knows indeed the open command of the Standard Suite, but it’s actually not used in iTunes”
Thank you very much for your quick reply, but I think you misunderstand my question. I understand your point about the “open” command, but my problem is not with that command. Let me use a different example, which does not reference the “open” command. Please consider the following two scripts:
–this script works:
tell application “iTunes”
set my_file to alias “Macintosh HD:test.mp3”
play my_file
end tell
–this one doesn’t:
tell application “iTunes”
set my_text to “Macintosh HD:test.mp3”
set my_file to alias my_text
play my_file
end tell
Why? The problem is that iTunes is insisting on a literal string, rather than accepting a text variable as the equivalent. This makes no sense. As I showed in my earlier example, other apps (like Finder) have no problem if you ask them to use the “alias” command in connection with a text variable.
I hope I did a better job of explaining the problem. Thanks again.
To set up paths and files is actually not the job of an application like iTunes.
Personally I try to target applications only to execute appropriate commands
e.g.
set my_text to "Macintosh HD:test.mp3"
set my_file to alias my_text
tell application "iTunes" to play my_file
or use a coercion (as alias) instead of a specifier
tell application "iTunes"
set my_text to "Macintosh HD:test.mp3"
set my_file to my_text as alias
play my_file
end tell