Newbie can't integrate with iTunes

Discussion and announcements regarding the Mac port… er, original version of Oolite.

Moderators: winston, another_commander

BiggJazza
Mostly Harmless
Mostly Harmless
Posts: 2
Joined: Sun Jan 17, 2010 12:38 am

Newbie can't integrate with iTunes

Post by BiggJazza »

Hi,
Just installed the game, getting to know the commands and the like, but cannot for the life of me get the game to integrate with iTunes. I have the 3 suggested playlists created and populated with songs, iTunes open, Oolite open, no sound. The reference suggests i/tunes integration should be switched 'ON', but i cannot find this in the options, only a toggle for Music.

Running Snow Leopard on iMac, Oolite 1.73.4

Any help gratefully received.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

The Music switch has three settings (under Mac OS X): Off, On and iTunes. (Although switching to iTunes freezes it for several seconds under Snow Leopard, I just discovered.)
BiggJazza
Mostly Harmless
Mostly Harmless
Posts: 2
Joined: Sun Jan 17, 2010 12:38 am

Post by BiggJazza »

Sorted thanks, although initially Oolite was closing iTunes! Got some Pink Floyd in there now, gonna try some practice docking on the object that you're first presented with when leaving 'In Dock'. Presume that's why it's there (?).
Love your ranking Ahruman :D
User avatar
Corny
---- E L I T E ----
---- E L I T E ----
Posts: 363
Joined: Sun Dec 20, 2009 11:50 am
Location: (northern) Germany

Re: Newbie can't integrate with iTunes

Post by Corny »

Did anything change meanwhile? I can't get it to work at all.
I have three playlists that worked before - Oolite-Docked, Oolite-Docking and Oolite-Inflight - and I'm trying it with vanilla Oolite in case an OXP breaks it. Music is set to iTunes, I quit iTunes and started it in case something like a half-played song stops the integration from working.
Oolite 1.77
iTune 11.0.2 (26)
Mac OS X 10.8.2

Here's what I find in the log about it:
14:08:24.867 [sound.music.iTunesIntegration.failed]: ootunes returned :{
NSAppleScriptErrorAppName = iTunes;
NSAppleScriptErrorBriefMessage = "Can\U2019t set song repeat of user playlist id 44877 of source id 73 to all.";
NSAppleScriptErrorMessage = "iTunes got an error: Can\U2019t set song repeat of user playlist id 44877 of source id 73 to all.";
NSAppleScriptErrorNumber = "-10006";
NSAppleScriptErrorRange = "NSRange: {157, 37}";
User avatar
JazHaz
---- E L I T E ----
---- E L I T E ----
Posts: 2991
Joined: Tue Sep 22, 2009 11:07 am
Location: Enfield, Middlesex
Contact:

Re: Newbie can't integrate with iTunes

Post by JazHaz »

Is there any chance of getting iTunes integration for Windows users?
JazHaz

Gimi wrote:
drew wrote:
£4,500 though! :shock: <Faints>
Cheers,
Drew.
Maybe you could start a Kickstarter Campaign to found your £4500 pledge. 8)
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!
Hans Olo
Dangerous
Dangerous
Posts: 88
Joined: Fri Mar 01, 2013 3:01 am

Re: Newbie can't integrate with iTunes

Post by Hans Olo »

JazHaz wrote:
Is there any chance of getting iTunes integration for Windows users?
I dunno... integration in apple probably runs an applescript to communicate with iTunes, so unlikely. Unless I'm wrong :wink:
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

Corny wrote:
Did anything change meanwhile? I can't get it to work at all.

Oolite 1.77
iTune 11.0.2 (26)
Mac OS X 10.8.2
Same in my log with Oolite 1.77 and OSX 10.6:

Code: Select all

[sound.music.iTunesIntegration.failed]: ootunes returned :{
    NSAppleScriptErrorAppName = iTunes;
    NSAppleScriptErrorBriefMessage = "AppleEvent timed out.";
    NSAppleScriptErrorMessage = "iTunes got an error: AppleEvent timed out.";
    NSAppleScriptErrorNumber = "-1712";
    NSAppleScriptErrorRange = "NSRange: {68, 26}";
}
[sound.music.iTunesIntegration.failed]: ootunes returned :{
    NSAppleScriptErrorAppName = iTunes;
    NSAppleScriptErrorBriefMessage = "Can\U2019t set song repeat of user playlist id 1821 of source id 73 to all.";
    NSAppleScriptErrorMessage = "iTunes got an error: Can\U2019t set song repeat of user playlist id 1821 of source id 73 to all.";
    NSAppleScriptErrorNumber = "-10006";
    NSAppleScriptErrorRange = "NSRange: {157, 37}";
}
Oolite is sending simple AppleScript commands to iTunes. I can't remember any Oolite change lately, but big changes in iTunes. I had other programs that no longer connected correct with iTunes 11.

EDIT:
I get the same errors in the log with Oolite 1.74. With that version, I am sure it always worked. Meaning that the problem is iTunes 11 that is no longer accepting the old commands.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

Any AppleScript experts on board? The whole current code used by Oolite is:

Code: Select all

- (void) playiTunesPlaylist:(NSString *)playlistName
{
	NSString *ootunesScriptString =
		[NSString stringWithFormat:
		@"with timeout of 1 second\n"
		 "    tell application \"iTunes\"\n"
		 "        copy playlist \"%@\" to thePlaylist\n"
		 "        if thePlaylist exists then\n"
		 "            set song repeat of thePlaylist to all\n"
		 "            set shuffle of thePlaylist to true\n"
		 "            play some track of thePlaylist\n"
		 "        end if\n"
		 "    end tell\n"
		 "end timeout",
		 playlistName];
	
	NSAppleScript *ootunesScript = [[[NSAppleScript alloc] initWithSource:ootunesScriptString] autorelease];
	NSDictionary *errDict = nil;
	
	[ootunesScript executeAndReturnError:&errDict];
	if (errDict)
		OOLog(@"sound.music.iTunesIntegration.failed", @"ootunes returned :%@", errDict);
}
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

It is probably 20 Years ago that I tried to write something in AppleScript. Above code reads in short:

Code: Select all

tell application "iTunes"
	copy playlist "Oolite-Docked" to thePlaylist
	if thePlaylist exists then
		set song repeat of thePlaylist to all
		set shuffle of thePlaylist to true
		play some track of thePlaylist
	end if
end tell
But when executing in the AppleScipt editor I get:

Code: Select all

tell application "iTunes"
	get playlist "Oolite-Docked"
		--> user playlist id 1789 of source id 72
	exists user playlist id 1789 of source id 72
		--> true
	set song repeat of user playlist id 1789 of source id 72 to all
		--> error number -1708
Resultaat:
error "iTunes kreeg een fout: song repeat of user playlist id 1789 of source id 72 kan niet worden ingesteld op all." number -10006 from song repeat of user playlist id 1789 of source id 72
It goes wrong with the 'all' parameter. But when opening the iTunes library I see:

Code: Select all

song repeat (off/one/all) : playback repeat mode
So it seems a correct syntax, and always was with iTunes. I know to little off AppleScript to see if this is a change of syntax, or simply a bug in iTunes itself. Any takers?
megangel1
Harmless
Harmless
Posts: 1
Joined: Sat Dec 07, 2013 11:19 am

Re: Newbie can't integrate with iTunes

Post by megangel1 »

In OOMusicController.m the code:-

Code: Select all

NSString *ootunesScriptString =
[NSString stringWithFormat:
@"with timeout of 1 second\n"
" tell application \"iTunes\"\n"
" copy playlist \"%@\" to thePlaylist\n"
" if thePlaylist exists then\n"
" set song repeat of thePlaylist to all\n"
" set shuffle of thePlaylist to true\n"
" play some track of thePlaylist\n"
" end if\n"
" end tell\n"
"end timeout",
playlistName];
throws errors but this could be changed to something like:-

Code: Select all

[NSString stringWithFormat:
@"with timeout of 1 second\n"
" tell application \"iTunes\"\n"
" stop\n"
" copy \"%@\" to ThePlayList\n"
" if playlist ThePlayList exists then\n"
" play playlist ThePlayList\n"
" tell application \"System Events\" to tell process \"iTunes\"\'s menu bar 1\'s menu bar item \"Controls\"\'s menu 1\'s menu item \"Repeat\"\'s menu 1\n"
" perform action \"AXPress\" of menu item \"All\"\n"
" end tell\n"
" else\n"
" set newalias to location of some track of playlist 1\n"
" set newlist to make new playlist\n"
" set name of newlist to ThePlayList\n"
" tell application \"System Events\" to tell process \"iTunes\"\'s menu bar 1\'s menu bar item \"Controls\"\'s menu 1\'s menu item \"Repeat\"\'s menu 1\n"
" perform action \"AXPress\" of menu item \"All\"\n"
" end tell\n"
" tell application \"System Events\" to perform action \"AXPress\" of (first menu item of process \"iTunes\"\'s menu bar 1\'s menu bar item \"Controls\"\'s menu 1\'s menu item \"Shuffle\"\'s menu 1 whose name ends with \"Shuffle\")\n"
" add newalias to newlist\n"
" play newlist\n"
" end if\n"
" end tell\n"
"end timeout",
playlistName];
Which works (although it requires access for assistive devices to be enables in system preferences )

Recompile using Xcode and use result instead of existing Oolite.app.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

megangel1, thanks for the code. I haven't played, nor compiled Oolite for a long time.

Today I added your code to my source and Oolite can use I-Tunes integration again. And as you say, it asks for permission, but it will be quite clear for end-users what to change in the System preferences to give permanent permission.

But, although it now works, it still throws an error in the log:

Code: Select all

16:26:53.003 [sound.music.iTunesIntegration.failed] OOMusicController.m:387: ootunes returned :{
    NSAppleScriptErrorAppName = "System Events";
    NSAppleScriptErrorBriefMessage = "AppleEvent timed out.";
    NSAppleScriptErrorMessage = "System Events got an error: AppleEvent timed out.";
    NSAppleScriptErrorNumber = "-1712";
    NSAppleScriptErrorRange = "NSRange: {297, 47}";
}
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

Interesting. With a timeout of 5 seconds,I get the same errors in the log.

But setting the timeout to 30 seconds , I find in the log:

Code: Select all

16:38:58.189 [sound.music.iTunesIntegration.failed] OOMusicController.m:387: ootunes returned :{
    NSAppleScriptErrorAppName = "System Events";
    NSAppleScriptErrorBriefMessage = "Oolite heeft geen toegang voor hulpapparaten.";
    NSAppleScriptErrorMessage = "System Events got an error: Oolite heeft geen toegang voor hulpapparaten.";
    NSAppleScriptErrorNumber = "-1719";
    NSAppleScriptErrorRange = "NSRange: {296, 47}";
}
So, that is the reason for the time-out. An error in Dutch, meaning Oolite has no access to assistive devices. Even when I see in the preferences that access is granted.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

Now I know why the script of megangel1 is still throwing errors. Selecting menu-items of iTunes by name is language specific. When replacing "Controls" with "Regelaars" and "Turn On Shuffle" by "Schakel shuffle in", Oolite stops throwing errors and really turns on the shuffling option. But this is not a useful method if it is language sensitive.

A bit of googling gives a lots of hits, telling that the "Shuffle" and "Repeat" commands are removed from iTunes 11. And all come up with a variation of the script that uses the language dependent method that megangel1 gives. I could not find an official replacement if these functions. But looking in the apple script library, both methods should still be possible. Bug in iTunes 11?

Anyhow, just removing the two lines in the original script that set shuffle and repeat, makes that the scrips works again in Oolite. Not being able to set shuffle and repeat is not a big problem. iTines will now use the last settings for those.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6312
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Newbie can't integrate with iTunes

Post by Diziet Sma »

So Apple have language-specific commands hard-coded into different versions of iTunes? Talk about a brain-dead move. :roll:

Coming on top of the "goto bug" security hole, I guess this really does show that some of their programmers are still stuck in the '80s. :mrgreen:

(sorry if this comes across as Apple-bashing, but seriously.. such sloppy coding practice in this day and age is ridiculous)
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Newbie can't integrate with iTunes

Post by Eric Walch »

Diziet Sma wrote:
So Apple have language-specific commands hard-coded into different versions of iTunes?
It is not Apple doing that. Two functions are removed from the iTunes library (at least are not working) and scripters are replacing that by a method were the system is instructed to activate specific menu items. They just choose to do it by name instead by position in the menu. They just use the hardcoded name instead of position because it is easier to remember. And because 90% of the demoscripts you see around do it in that way.

I'm not familiar with Apple Script, but think that there must be a more sensible method.
Post Reply