Code/new Copy Singers: Difference between revisions

From kJams Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
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 *)", 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.
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 *)", 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, simple select "Services" from the kJams menu, and then select your saved service.
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.
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.



Revision as of 15:46, 10 March 2011

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 *)", 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!

on run {input, parameters}
	
	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 Value</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
	-- return tagValue
	-- 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 thisTagValue 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 thisTagValue to thisTagValue & 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 & thisTagValue & "/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
	repeat with i from 1 to count of Singers
		tell application "Finder"
			set Singer to item i of Singers
			make new alias file at singerPath to Singer
		end tell
	end repeat
	set kScriptCommand_RESCAN_VENUE to 19
	tell application "kJams Pro"
		docommand kScriptCommand_RESCAN_VENUE
	end tell
	return input
end run