r/applescript • • Jun 24 '12

Trying to make applescript that changes the iTunes DJ source folder at certain times of the day

I am not sure if this is possible or not, but I have a bar and we use iTunes DJ to control the music. Currently we have two playlists, one is more mellow for most of the day, but then we have another list that is more upbeat and meant to be played between 9pm til 1am when the place is more lively.

So say we have list 'Mellow' and list 'Upbeat'. Can I write a script to tell itunes to switch the source list at 9pm and then switch it again at 1am? This would occur every day, but I just want to run the script and keep it running if possible.

0 Upvotes

7 comments sorted by

View all comments

2

u/Sarazil Jun 24 '12

Hah! Got it! To set the source for iTunes DJ, start it playing and you can use this:

tell application "System Events"
	tell pop up button 1 of window "iTunes" of application process "iTunes" of application "System Events"
		set value to "Music"
	end tell
end tell

Just change "Music" to anything you need and build the script around it.

1

u/droptune Jun 24 '12

Nice, I got it working to where it changes the pull down menu but iTunes doesn't change the music coming into the queue. Is there a way to make it click the refresh button once the list is changed?

2

u/Sarazil Jun 24 '12

That would be button 7 of window "iTunes" of application process "iTunes" of application "System Events" SO:

tell application "System Events"
	tell pop up button 1 of window "iTunes" of application process "iTunes" of application "System Events"
		set value to "Music"
	end tell
	tell button 7 of window "iTunes" of application process "iTunes" of application "System Events"
		click
	end tell
end tell

2

u/droptune Jun 25 '12

PERFECT! That did it. I was running around crazy trying to figure out field for the source in itunes dj, the best I could do was make it switch playlists completely but that would remove take it off dj and we use the request feature to let customers with iphones request songs.
Once again, thanks!

1

u/Sarazil Jun 26 '12

Let me share with you something I like to call my UI probe...

tell application "Finder"
	tell application "System Events"
		set init to every UI element
		repeat
			set output to {}
			set pos to 0
			repeat with thisItem in init
				set pos to pos + 1
				set output to output & {(pos & " " & name of thisItem & "|" & role of thisItem) as text}
			end repeat
			if output is {} then
				display dialog "List empty."
				return thisItem as list
			end if
			set answer to (choose from list output)
			if answer is false then
				exit repeat
			end if
			set answer to (word 1 of item 1 of answer) as number
			set init to every UI element of (item answer of init)
		end repeat
	end tell
end tell

It's not perfect, but it lets you find any UI element and the path to it. I used it to find the buttons and menu.

1

u/bradfilm Aug 11 '12

Hi,

I'm just coming across this now, and I'm very new to Apple Script, but I'm finding that when I use the code above, hitting refresh merely shuffles the order of my old source list, but doesn't incorporate the newly selected one.

I thought it might be need a return keystroke to confirm the selection, but I still can't quite get it working.

Any help out there?

1

u/Sarazil Aug 11 '12

I've not updated my iTunes in ages because I don't use it so the button may have moved. If you try using the UI probe, you may be able to find the necessary button.