Code/new Copy Singers

From kJams Wiki
Jump to navigation Jump to search

So with the advent of "Venues" you may have run into the situation where a singer from another venue shows up out of the blue at the current venue, wanting to see their history list. Accessing it is kinda a nightmare, involving going to the Finder, drilling down until you find the right singer folder, creating an alias, and then copying that alias over to the current venue folder, followed by changing venues in kJams, and then changing it back again in order to force kJams to reload the current venue's Singers folder.

Well, I can't do anything about the kJams end of things, as that functionality is not currently exposed to an API like Applescript, but what I can do is automate the rest. After a full 1/2 day of work (mostly since I am a lousy programmer!) I managed to get the following working. You have two choices on how to use this. You can open Applescript Editor and paste the following code into a new script window, and save as an application, and then run as you would any other application. But better yet, open up Automator, select "Service" from the template choices on the opening splash screen, and then drag "Run AppleScript" from the Library onto the Stage. Change the "Service receives selected" popup to "no input", and "applications" to "kJams". (First choose "other…" from the popup menu, and then browse to kJams in the file selector.) Next, paste the following code over top of where is says "(* Your script goes here *)". Finally, change the first line where it says "set kJamsPath to "Users/yourusername/Music/kJams/kJams Library/" by replacing "yourusername" with, oddly, you user name (use your short user name) and save.

Then when you run kJams, and need this functionality, either run the application from where you saved it to, or if you saved it in automator as a service, simply select "Services" from the kJams menu, and then select your saved service. At that point just follow the prompts to tell the service which singers you want to transfer (you can transfer multiple singers at the same time.) This will put an alias in your current venue folder, thus letting that singer access his or her playlists from either venue.

If this is helpful, let me know here.

UPDATE: Thanks to recent additions to the kJams code and its exposure to AppleScript, I was able to fully automate the code. Use the following code now to perform the entire act of copying the singers' folders to the new venue AND actually making kJams recognize that the singers are in the new venue. Proceed with a small amount of caution, however, as you are on the cutting edge here, and you might get a little blood on you! In particular, it appears to expose a bug that causes kJams to go slightly bonkers, and possibly lose the copied singers' lists IF you already have an alias to the same singer(s) in that venue already. I am speculating that this is because you are trying to have multiple singers with the same ID, and kjams gets noticeably, and justifiably, upset. This should affect almost no one, and actually no one, if you don't mess around in your venues by hand and run this script hundreds of times, thus getting things royally confused in there, trying to test things out! As always, let me know how it is working!

P.S. as added goodness, in my testing, the new code NEVER caused server to fail to come back up due to an unreleased port! P.P.S. If you totally love this, please feel free to paypal the author.

<iimg>https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=manifold_sky%yahoo%2ecom&item_name=kJams%20Video%20Backdrop%20Donation&no_shipping=2&no_note=1&currency_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8 !paypal.gif</iimg>

set kJamsPath to "/Users/YourUserName/Music/kJams/kJams Library/"
set kJamsLibraryPath to kJamsPath & "Library.xml"
set XMLfile to (POSIX file (kJamsLibraryPath))
set Paras to paragraphs of (read XMLfile)

-- we cycle through the list and extract the portion between the tag we're interested in
-- we know that the tag we want is immediately after "<key>Current Venue</key>"
set tagValue to {}
repeat with i from 1 to count of Paras
	if item i of Paras contains "Current Venue" then -- first we find the tag we're interested in
		set tagValue to item (i + 1) of Paras
		exit repeat
	end if
end repeat

-- next we extract each value from the found tags knowing that the value is between "<string>" and "</string>
repeat with i from 1 to count of tagValue
	set thisTag to item i of tagValue
	set venueName to ""
	if thisTag is ">" then
		repeat with k from (i + 1) to count of tagValue
			set thisTag to item k of tagValue
			if thisTag is "<" then exit repeat
			set venueName to venueName & thisTag
		end repeat
		exit repeat
	end if
end repeat
-- thisTagValue
set kJamsPath to kJamsPath & "Venues/"
set venuePath to (POSIX file (kJamsPath))
set singerPath to (POSIX file (kJamsPath & venueName & "/Singers"))
set Singers to (choose folder default location alias venuePath with prompt "Choose singers to copy to the current venue" with multiple selections allowed) as list

tell application "Finder"
	make new alias file at singerPath to Singers
end tell

set kCurSongTime_REMAINING to 2
set kScriptCommand_RESCAN_VENUE to 19
set kScriptCommand_SHOW_ROTATION to 20
set kScriptCommand_HIDE_SHOWSCREEN to 21
set kScriptCommand_IS_SHOWSCREEN_SHOWING to 22
set kScriptCommand_GET_SHOW_ROTATION_TIME_REMAIN to 23
tell application "kJams Pro"
	set rotationCueTime to docommand kScriptCommand_GET_SHOW_ROTATION_TIME_REMAIN
	set timeRemaining to get time kCurSongTime_REMAINING
	set showScreenIsShowing to docommand kScriptCommand_IS_SHOWSCREEN_SHOWING
	
	if showScreenIsShowing = 0 then
		if rotationCueTime is equal to timeRemaining then docommand kScriptCommand_SHOW_ROTATION
		
	end if
	docommand kScriptCommand_RESCAN_VENUE
end tell

If you want to make into a service,