In my iTunes AppleScript (using AppleScript 2.0.1 under Mac OS X 10.5.5), I am trying to test the “video kind” property of a track. This property is an enumerated type listed in the dictionary as (none/movie/music video/TV show). I can test against the last 3 types, but I am having a problem with “none”.
So, this works …
if (video kind of track trackIndex of library playlist 1) is not in {movie, music video, TV show} then
but this does not …
if (video kind of track trackIndex of library playlist 1) is none then
They both compile and execute, but the second statement retrieves no records, while the first retrieves many records.
I am guessing that the “none” type is so generically named that AppleScript may be assuming the wrong value (from another app or something).
As I thought about it, various properties and enumerated types are so generically named that they must often conflict with other applications or within the same application.
So, can someone tell me how to specify that I am referring to the
I had tried that before (and once again now to be safe ;)) based on a code snippet I saw in Doug’s iTunes AppleScripts. However, for me (with AppleScript 2.0.1, Mac OS X 10.5.5, and iTunes 8.0.1), it yielded zero results. Does it work for you?
I imagine that AppleScript can not translate an enumerated type to a text string. If anything, it should be able to at least translate it to a number, but when I try to coerce it “as integer” (assuming the enumerated type translates to a 0), it says this can’t be done
I’ve tested it with this (silly) code, my playlist “Podcasts” contains both none and movie tracks
property myPlayList : "Podcasts"
tell application "iTunes"
repeat with trackIndex from 1 to (count tracks of playlist myPlayList)
set {video kind:video_kind, name:_name} to track trackIndex of playlist myPlayList
if video_kind as text is "none" then
display dialog _name & " - " & "none"
else
say video_kind as text
end if
end repeat
end tell
So, with your script, I realize that my “video kind” values translate to strange “constant-type” text. For instance, instead of “none”, my “video kind” tracks with “none” values get translated to the text for the core constant: “«constant ****kVdN»”. If I test against this strange string, then I get the result I want! So, thanks for pointing me in that direction.
Beyond this, do you know if there is a setting or something that I could change which is causing me to get these different results than you (and others)? So, I can test against the English-like values.
I have no other “tell” block defined in my script. Either way, to keep it simple, we can focus on your simple script that I tested, since I have the same issue with it.
I am sure I have the “Standard Scripting Additions” installed (even though I do not believe I explicitly installed it), since I can use the “display dialog” and other such commands. Is the “Standard Scripting Additions” what you are referring to? If so, do you also have it installed, since you do not have the problem with your simple script?
By the way, I just thought of something. For major performance benefits, I am running all my iTunes AppleScripts from the iTunes Scripts folder/menu. Perhaps, since it is running internal to iTunes there are some issues … are you running it like this or externally
By the way, when you run a script within an application framework, is the “tell” block still needed for that application?
Standard Additions are installed anyway, so I don’t refer to this.
I’m using the commercial Script Editor “Script Debugger” by LateNight Software,
but it could be, that the scripts behave different being run form the script menu or Script Editor / Script Debugger.
I use Apple Script Editor to compile/save as a “script”
Like other Mac applications, iTunes has its own “script menu” to directly execute scripts (only those located in the /Users//Library/iTunes/Scripts folder). This is different than the general “script” menu that can be added to the menu bar with the AppleScript utility.
When I ran your simple script from within the iTunes script menu, it would not identify “none”. When I ran it externally (from within the Apple Script Editor), it worked fine and properly identified “none”.
When I ran my iTunes AppleScripts “externally” (from Script Editor or as a saved application), they were extremely slow … almost 30 minutes to process 9,500 tracks! However, when I run the same scripts from within the iTunes script menu (and saved as “scripts” not “applications”), the same logic takes about 30 seconds! If you have iTunes scripts and have not already done so, I HIGHLY recommend running them from the iTunes script folder/menu.
I noticed that Mac Office 2008 Excel has a similar script menu (again, not related to the general “script menu”) to run Excel AppleScripts.
So, by “within an application framework”, I am referring to the script being executed/called from “within an application” - just like iTunes and Excel do from their own script menus. This execution of scripts seems to communicate much faster with the application’s framework (referencing iTunes playlists, etc.). In addition, I am guessing that here is where enumerated types with conflicting “friendly” names have issues and are forced to be resolved with the internal codes.
I just started AppleScripting and I consider the Apple Script Editor to be pretty decent. I see that I can move to the free XCode development environment (I downloaded it with the iPhone SDK) when I am ready for more sophistication. Any reason you prefer this third-party script editor that you use?
So are there other Scripting Additions that I can install to get more power? Are these from Apple?
I got it. You need always to use application tell blocks. AppleScript works completely independent from any application
As the name implies, Script Debugger is perfect to debug scripts with step by step execution, breakpoints etc.
Xcode can do similar things, but the preferred language of Xcode is Objective-C. In my opinion Script Debugger is more powerful than Xcode concerning AppleScript
There are no further scripting additions provided by Apple. But there are lots of thirty party additions. The power depends on what you’re going to accomplish