Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
I am trying to use Chronosync to sync my iTunes library on one machine to my iTunes library on another machine, and Chronosync has an option to run a script before and after the synchronization occurs, which in my case would be great to run a script that quits the iTunes application prior to syncing it, then re-opens iTunes after syncing has completed.

Can someone please help create two applescripts... one to quit iTunes, and the second to start iTunes.

Thanks!

For reference, here is the ChronoSync pre/post synchronization script interface:

img_20110523_014239.png
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Code:
tell application "iTunes"
	quit
end tell

Code:
tell application "iTunes"
	activate
end tell

In all honesty I can't believe Google could not have told you that...
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
Thanks! That was probably brainlessly easy for you :)

I have a bit of a tougher one that perhaps you might be able to give me a hand with...

If I am using ChronoSync to mirror my iTunes library from on MacPro to the iTunes library on my iMac (which is also on the same network and has a static IP address), any thoughts on whether or not a single applescript launched from the MacPro ~ which will be the one initiating the chronosync synchronization ~ would be able to quit iTunes running on both machines, then reopen iTunes on both machines after the sync is complete?

To clarify... the script you helped me out with will do the trick for quitting the itunes library of the mac pro, but if itunes us running on my iMac at the time the sync occurs, then I'm still likely to run into issues with the sync procedure.

Any suggestions would be greatly appreciated... Thanks!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Not easily. If you open System Preferences and look in the Sharing preferences you'll see something called "Remote Apple Events". I suspect this could be used to bridge AppleScript across machines but I've never used this.

The easier option would be to find something that can do this already and has been built for you…

Edit: OK. This actually looks possible!

Take a look at http://dougscripts.com/itunes/itinfo/remcontrol.php

If we change the first script to:
Code:
set remMachine to "eppc://username:userpass@remote_ip"

using terms from application "iTunes"
	try
		tell application "iTunes" of machine remMachine
			quit
		end tell

	on error errM number errN
		display dialog (errM & space & errN)
	end try
end using terms from

tell application "iTunes"
	quit
end tell

Then this will connect to IP remote_ip as username with password userpass and tell iTunes on that machine to quit. The it'll tell the local iTunes to quit. Obviously you replace username, userpadd and remote_ip with the correct values. And turn on Remote Apple Events on both machines (or maybe only the remote one?)
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
the script you suggested worked perfectly to quit iTunes on both machines, but when I tried it in reverse to re-open itunes on both machines (the post-synchronization script) it failed to launch itunes on the remote machine and it gave me the following error message:
img_20110523_031323.png


Doug from Doug's iTunes scripts does say that following at the beginning of the page you referenced:
"The iTunes application on the remote machine must already be activated in order for an AppleScript on the local machine to control it. I couldn't get it to activate via a remote script."

It would be great if someone could help me figure this one out because at this point I'm so close to pulling off the impossible that it'd be tragic to fail now :confused:

Thanks for your help! Look forward to seeing if anyone can help figure this one out.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Try this to launch iTunes on the remote machine (found in 2 seconds using Google)

Code:
 tell application "Finder" of machine "eppc://username:password@powermac.local" to open ":Applications:iTunes"
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
I'm having a difficult time authenticating when using the script to remotely quit itunes. It says I can use my username (which is my first and last name with a space in between), or I can use my Rendezvous name (somename.local)... I am randomly getting authentication failed messages when I try running the applescript. A couple times after running the script, it gave me a popup dialog asking me to enter my username and apassword and log and it gave me the option to save the login info to my keychain which I did, but a subsequent attempt at running the script has failed...

Not really sure what I am supposed to do here to get it to connect to the remote computer consistently.

Any suggestions would be greatly appreciated... Thanks!
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
assuming my username is "FirstName LastName", I've tried configuring the script as follows:

set remMachine to "eppc://FirstName LastName:password@10.0.1.??"

using terms from application "iTunes"
try
tell application "iTunes" of machine remMachine
quit
end tell

on error errM number errN
display dialog (errM & space & errN)
end try
end using terms from

tell application "iTunes"
quit
end tell


assuming my Rendezvous name is "Office (Computer)" which in rendezvous speak gets translated into "Office-Computer.local", I've also tried configuring the script as follows:

set remMachine to "eppc://Office-Computer.local:password@10.0.1.??"

using terms from application "iTunes"
try
tell application "iTunes" of machine remMachine
quit
end tell

on error errM number errN
display dialog (errM & space & errN)
end try
end using terms from

tell application "iTunes"
quit
end tell

Neither approach works… what am I doing wrong here? Thanks!

EDIT: Ignore the happy face in the code above... that's meant to be a ':' followed by a 'P' which got inadvertently translated into an emoticon :)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Usernames with spaces are probably an issue. Try using your shortname. For example my username is Robert Duncan but my shortname is robbie. Or try using %20 instead of a space which might work.

Also the Rendezvous name of the computer is nothing to do with "you": it's the machine name, not a username. It's not even remotely similar. It might work in place of the IP address but you can't log in using that as a username.

Edit: instead of using quote blocks use code blocks:
Code:
:p :) :D
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
Try this to launch iTunes on the remote machine (found in 2 seconds using Google)

Code:
 tell application "Finder" of machine "eppc://username:password@powermac.local" to open ":Applications:iTunes"

I tried this and it gives me the following error:

img_20110523_035744.png
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Maybe try
Code:
tell application "Finder" of machine "eppc://username:password@powermac.local" to open POSIX file "/Applications/iTunes.app"
 

m021478

macrumors 6502
Original poster
Nov 23, 2007
378
5
that worked! You pulled off the impossible! The cycle is complete. Now ChronoSync can quit iTunes on both machines, mirror the library from the Mac Pro to the iMac, then relaunch the libraries on both machines once the process is complete. PERFECT!

You rock! Thanks so much for your help!

Just for the record for anyone who stumbles onto this thread in the future -

...here is the script that closes iTunes on both machines:

Code:
set remMachine to "eppc://username:password@powermac.local"

using terms from application "iTunes"
	try
		tell application "iTunes" of machine remMachine
			quit
		end tell
		
	on error errM number errN
		display dialog (errM & space & errN)
	end try
end using terms from

tell application "iTunes"
	quit
end tell

... and here is the code that opens iTunes back up again on both machines:

Code:
tell application "Finder" of machine "eppc://username:password@powermac.local" to open POSIX file "/Applications/iTunes.app"

tell application "iTunes"
	activate
end tell

Be sure to enable 'Remote Apple Events' in the 'Sharing' pane of the System Preferences

Thanks again for all your help with this one!
 

bonimac

macrumors newbie
Feb 4, 2010
19
1
Amazing guy's, it worked for me from the first time!
thank you so much (from the future) :)

never expected how to find out to do this from my iMac to Mac mini media server.
i'm so happy, thanks thanks thanks!
:D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.