I like Apple’s Dashcode more than I should. It is a powerful Webapp creator that is a bit under-supported. I don’t think it gets the love, or the hacker support, that it deservers. So, I find myself trying to make it do stuff it wasn’t originally designed for. Recently, I’ve been using it to create skins for some non-iOS mobile apps. As part of a budding workflow, I wrote a script to copy an existing Dashcode project and have it ready for the new project, including published to the right (read – ‘new’) location instead of the old location associated with the previous project. Well, the challenge, is that Dashcode has the concept of a “Deployment Directory” that should point to my new workspace, not my old workspace. This article describes how to programmatically change the “Deployment Directory”
So, how can we script a solution for this?
Although Dashcode project looks like a single executable file, it is actually a Finder package with lots of stuff inside. The trick is looking to see if the deployment path is stored in something we can mess with. It turns out the value is stored in jj.wdgtuser (my user name is jj). Sweet!
The good news is that is stored in the .xml file – that is also the bad news. Apple’s xml formats always sort of sucks, so getting to our variable isn’t super easy, unless you think predicate XPATH programming is super easy.
Here are the general steps I used to accomplish scripting the deployment path:
- Ensure Dashcode is not running
- Find the current username so you open the right .wdgtuser file.
- Use XPATH
- find the dict element whose previous sibling is a key element with a value of ‘DeploymentOptions‘
- Given the above context, use XPATH to
- find the string element whose previous sibling is a key element with a value of ‘Path’
The hard part here, of course, is finagling XPATH. Here is the PHP code I used, but you’ll need to modify it for your own means:
$plistPath = baseDir($target)."/skins/{$skinName}.dcproj/jj.wdgtuser";
$xml = simplexml_load_file($plistPath);
$result = $xml->xpath("//dict/dict/string[preceding-sibling::key[1][node()='Path']]/node()");
$result[0][0] = $newDeploymentPath;
$xml->asXML($plistPath);
Here is a stab at explaining the XPATH above:
Hope this helps some other poor soul that wanders into the wilderness of Dashcode hacking.