Note: I am pretty new to AppleScript, though I have been programming for many years, so should know fundamentally what I’m doing.
I am trying to automate a currently very manual and time consuming task at my work. It mostly involves copying one folder to a new place, renaming all the files, and changing file references in XML documents. Reading XML seems to work just fine, but modifying/writing that XML I cannot get to work at all. Since this script will live past my own employment and be used by others, I’d prefer to not use third party software, though if I get confirmation that it can ONLY be done that way, I’ll bite the bullet.
I’ve tracked the non-functional bit down to this:
log (new_reference as text) set value of curAttribute to (new_reference as text) log value of curAttribute as text
curAttribute is an XML attribute, and setting the value of it does not stick. The first log shows the value that I want, the second log shows the old value. I get no errors, it just doesn’t modify the contents of the XML as I would expect.
The parts surrounding the most relevant bit are below:
tell application "System Events" set theXMLFile to XML file (tmpFile as string) tell theXMLFile log text of contents of theXMLFile set root to XML element "xsl:stylesheet" of theXMLFile set imports to XML element "xsl:import" of root repeat with curLine in imports set attributeValues to XML attributes of curLine repeat with curAttribute in attributeValues set attributeName to name of curAttribute if (attributeName = "href") then set AppleScript's text item delimiters to the currentName set the item_list to every text item of ((value of curAttribute) as string) set AppleScript's text item delimiters to the new_name set new_reference to the item_list as string set AppleScript's text item delimiters to "" log (new_reference as text) set value of curAttribute to (new_reference as text) log value of curAttribute as text -- set value of (item p of (XML attributes of (item i of imports))) to new_reference end if end repeat end repeat end tell