Page 1 of 2

Newbie can't integrate with iTunes

Posted: Sun Jan 17, 2010 12:46 am
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.

Posted: Sun Jan 17, 2010 1:37 am
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.)

Posted: Sun Jan 17, 2010 12:42 pm
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

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 1:08 pm
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}";

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 1:16 pm
by JazHaz
Is there any chance of getting iTunes integration for Windows users?

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 1:23 pm
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:

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 5:13 pm
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.

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 5:28 pm
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);
}

Re: Newbie can't integrate with iTunes

Posted: Tue Mar 19, 2013 7:56 pm
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?

Re: Newbie can't integrate with iTunes

Posted: Sat Dec 07, 2013 11:22 am
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.

Re: Newbie can't integrate with iTunes

Posted: Sat May 10, 2014 2:25 pm
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}";
}

Re: Newbie can't integrate with iTunes

Posted: Sat May 10, 2014 2:56 pm
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.

Re: Newbie can't integrate with iTunes

Posted: Thu May 15, 2014 10:48 pm
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.

Re: Newbie can't integrate with iTunes

Posted: Fri May 16, 2014 4:25 am
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)

Re: Newbie can't integrate with iTunes

Posted: Fri May 16, 2014 6:08 am
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.