Code/new Copy Singers: Difference between revisions
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
If this is helpful, let me know [http://karaoke.kjams.com/forum/viewtopic.php?f=1&t=1377 here]. | If this is helpful, let me know [http://karaoke.kjams.com/forum/viewtopic.php?f=1&t=1377 here]. | ||
UPDATE: | |||
Thanks to recent additions to the kJams 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! | |||
<pre> | <pre> | ||
set kJamsPath to "Users/yourusername/Music/kJams/kJams Library/" | on run {input, parameters} | ||
set kJamsLibraryPath to kJamsPath & "Library.xml" | |||
set XMLfile to (POSIX file (kJamsLibraryPath)) | set kJamsPath to "Users/yourusername/Music/kJams/kJams Library/" | ||
set Paras to paragraphs of (read XMLfile) | set kJamsLibraryPath to kJamsPath & "Library.xml" | ||
-- we | set XMLfile to (POSIX file (kJamsLibraryPath)) | ||
-- we know that the tag we want is immediately after "<key>Current Value</key>" | set Paras to paragraphs of (read XMLfile) | ||
set tagValue to {} | -- we cycle through the list and extract the portion between the tag we're interested in | ||
repeat with i from 1 to count of Paras | -- 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 | |||
end repeat | exit repeat | ||
-- return tagValue | end if | ||
-- next we extract each value from the found tags knowing that the value is between "<string>" and "</string> | end repeat | ||
repeat with i from 1 to count of tagValue | -- 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 | |||
end repeat | exit repeat | ||
thisTagValue | end if | ||
set kJamsPath to kJamsPath & "Venues/" | end repeat | ||
set venuePath to (POSIX file (kJamsPath)) | thisTagValue | ||
set singerPath to (POSIX file (kJamsPath & thisTagValue & "/Singers")) | set kJamsPath to kJamsPath & "Venues/" | ||
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 | set venuePath to (POSIX file (kJamsPath)) | ||
repeat with i from 1 to count of Singers | 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 | end tell | ||
end | return input | ||
end run | |||
</pre> | </pre> | ||
Revision as of 11:58, 5 January 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, simple 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 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!
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