iTunes script crashes iTunes at times, not always

I have two scripts for iTunes which I use to switch between the full window view and the miniplayer window. I’ve used them on a DragThing palette for years, but recently they have begun to cause iTunes to quit abruptly (but not every time).

I’m seeing this with iTunes 10.5 (141) and AppleScript Version 2.2.1 (100.1) while using OS 10.5.8.

Any suggestions as to what’s causing the problem and/or how to avoid the crashes would be greatly appreciated.

Here’s one of the scripts:

do_menu("iTunes", "View", "Switch to Mini Player")

on do_menu(iTunes, View, "Switch to Mini Player")
	try
		-- bring the target application to the front
		tell application iTunes
			activate
		end tell
		tell application "System Events"
			tell process iTunes
				tell menu bar 1
					tell menu "View"
						click menu item "Switch to Mini Player"
					end tell
					
				end tell
			end tell
			return true
			
		end tell
	end try
end do_menu

Try sticking that " click menu item “Switch to Mini Player”" inside a try block
Something like:

tell application "System Events"
	-- the rest of your 'tells' go here
	try
		click menu item "Switch to Mini Player"
	on error x
		say x
	end try
end tell

I expect the ‘Switch to Mini Player’ menu item, or its menu bar is sometimes missing
The above code should tell you that.

Hi,

why not


tell application "iTunes"
	set minimized of window "iTunes" to true
end tell

Thanks, both great suggestions.

I’ve employed Stefan’s and it is working, not only that, but it seems faster than my original script.

So, unless I come back to the thread, I called this one SOLVED.