Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Modified version for fast user switching environmnent' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Modified version for fast user switching environmnent
Authored by: jfaughnan on Nov 10, '05 09:17:23PM
This my first attempt at doing anything with Javascript. I've only begun to test it, but I think it's the right track. The problem with two users on one machine is that you have to tell AppleScript which user session to get the tracks from. The capability to do this was apparently introduced in 10.3 but it didn't work. In 10.4 its seems to work, but it's almost completely undocumented. In fact, this may be the first example of this that Google might index!

-- Faughnan modified 11/10/05
-- jfaughnan@spamcop.net
-- I know nothing of AppleScript and there's not much documentation (ie. none) on how to work with a FUS application. I'm indebted to Matt Neuberger for a key hint.
-- for this to work the shared iTunes library must be on a share the client can accces. I moved the library to a "public folder"
-- user running script must either have admin privileges on local machine or use an admin password on request
-- http://www.macosxhints.com/article.php?story=20050215130254540
-- http://developer.apple.com/releasenotes/Carbon/AppleEvents.html
-- eppc://username:password@machinename.local
-- http://lists.apple.com/archives/applescript-implementors/2005/Aug/msg00055.html
-- http://www.apple.com/applescript/releasenotes/110OSX.html

property theDateofLastSync : "" -- date of last sync
property theRemoteiTunes : "" -- application reference for iTunes in other user session

set theDateofLastSync to ((current date) - 1 * days)
-- set theRemoteiTunes to application "iTunes" of machine "eppc://adminusername:password@localhost/?uid=504&pid=1853" (uname and password NOT TESTED)

(*=== Main Run ===*)

if theDateofLastSync is "" then set theDateofLastSync to ((current date) - 1 * days) -- force date for first run
if theRemoteiTunes is "" then
	choose remote application
	set theRemoteiTunes to result
end if

-- chat with other machine
set GotsomeTracks to true
try
	with timeout of 30000 seconds
		-- tell application "iTunes" of machine theSharedTunes
		tell theRemoteiTunes
			using terms from application "iTunes"
				activate
				set theListofTracks to location of file tracks of library playlist 1 where date added > theDateofLastSync
				--	set NumTracks to count of items of theListofTracks
			end using terms from
		end tell
	end timeout
on error
	set GotsomeTracks to false
end try

-- back to this Machine
set SyncedOK to false
if GotsomeTracks then
	set SyncedOK to true
	set NumTracks to count of items of theListofTracks
	try
		tell application "iTunes" -- of machine theClientTunes
			if (NumTracks) is greater than 0 then
				repeat with alocation in theListofTracks
					add alocation to library playlist 1
				end repeat
			end if
		end tell
	on error
		set SyncedOK to false
	end try
end if

display dialog (NumTracks as text) & " tracks were added to the library."

---
--
John Faughnan
jfaughnan@spamcop.net
www.faughnan.com

[ Reply to This | # ]