Shuffle code

wats wrong with this code that turns the playlist shuffle on?

on mouse down theObject event theEvent
	set image of image view 9 of window 0 to load image "d_shuffle"
end mouse down

on mouse up theObject event theEvent
	tell application "iTunes"
		set player to shuffle of playlist
		if player is true then
			set player to false
		else
			set player to true
		end if
	end tell
	set image of image view 9 of window 0 to load image "shuffle"
end mouse up

You aren’t telling iTunes which playlist to get information from. Try using this:

tell application "iTunes"
	set player to shuffle of current playlist
end tell

Model: Mac mini
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)

Hi,

im a newbie so plz dont kill me when I say: none of this works for me (OS 10.4.11).
I would need a script which can switch the shuffle on or off.

Thanks for any help.

Hi Niklas, put this in your on clicked handler

if the name of theObject is "shufflebutton" then
tell application "iTunes"
				if shuffle of view of browser window 1 is equal to false then
					set shuffle of view of browser window 1 to true
				else
					set shuffle of view of browser window 1 to false
				end if
				
			end tell
end if

there might be a way to shorten that but at least it works

Hi,

of course it doesn’t work, there is no command to set the shuffle property.
This toggles the value of shuffle of the current playlist


tell application "iTunes"
	try
		tell current playlist to set shuffle to not (get shuffle)
	end try
end tell

the try block avoids an error, if no playlist is selected

i knew you could use the get(not shuffle), i tried this before posting my response but it wouldn’t work in regular ScriptEditor, so i posted my crappier version

Hmm, thank you guys for your response!

Unfortunately both solutions dont work for me (I pasted them into Script Editor, on the first i get the error “The variable theObject is not defined.”, on the second i get nothing, no shuffle and no error.).
Maybe I’m doing something very wrong here, so please tell me what I could have done different.

And to clear things out: I got an application for my gamepad, which can execute scripts with one button pushed; in the moment im trying to get my gamepad into a remote control, which also should work when itunes isnt active.

G’day and thanks

This is the Xcode forum. :wink:
Hendo’s solution is part of a handler in Xcode. You can just omit the first and last line

My solution works here on a G5 with 10.5.4

Great great great :slight_smile:

thank you for that hint. it’s working!

See you guys with my next question soon.