Hi, Am 17.08.2010 um 17, 08:39 schrieb LuKreme:
> I would like to sort all the <dict> … </dict> entries in a .plist file at a > certain level in a plist/xml file. > > > basically, the file is the Extension.plist in > $HOME/Library/Safari/Extensions, and I want to sort all the dict entries that > are under the key "Installed Extension" according to the contents of the > string after the key "Archived File Name" Basically, you could try the following steps (you might want to apply this brute force method on a copy of your original file): 1) Remove all line breaks 2) Add line breaks before the dict elements by searching <dict> replace with \r& 3) Add a line break after the last </dict> element (this could also be done with grep by searching </dict>(.+)\Z and replacing with </dict>\r\1 4) Now you have every dict entry on a single line. Select all dict-lines and use the Sort Lines command on them (and only on them!) 5) Use Markup > Utilities > Format to make the file pretty again. The whole thing is hard to automatize as you have to select the lines to be sorted manually in step 4. You could fiddle on an applescript solution to make that selection but this might be a cumbersome task. You should also apply the replace actions only on the appropriate selection if the file contained other array elements you don't want do be sorted. Maybe this quick and dirty solution might be good enough for you if this is a one time only task. If you have to deal with this kind of XML transformations more often you should take a serious look at XSLT. Regards, Roland > here is an example: > > <key>Installed Extensions</key> > <array> > <dict> > <key>Archive File Name</key> > <string>FaceBlock-1.safariextz</string> > <key>Bundle Directory Name</key> > <string>FaceBlock-1.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > <dict> > <key>Archive File Name</key> > <string>Validate.safariextz</string> > <key>Bundle Directory Name</key> > <string>Validate.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > <dict> > <key>Archive File Name</key> > <string>AdBlock-1.safariextz</string> > <key>Bundle Directory Name</key> > <string>AdBlock-1.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > > > and it should be: > > <key>Installed Extensions</key> > <array> > <dict> > <key>Archive File Name</key> > <string>AdBlock-1.safariextz</string> > <key>Bundle Directory Name</key> > <string>AdBlock-1.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > <dict> > <key>Archive File Name</key> > <string>FaceBlock-1.safariextz</string> > <key>Bundle Directory Name</key> > <string>FaceBlock-1.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > <dict> > <key>Archive File Name</key> > <string>Validate.safariextz</string> > <key>Bundle Directory Name</key> > <string>Validate.safariextension</string> > <key>Enabled</key> > <true/> > </dict> > > Of course, there are a lot of keys, so I want to automate this. > > The dict declarations to sort are all 2 tabs deep in the file. > > Oh, it might be nice if I could also then sort on the Enabled key to put all > the entries with <false/> at the end? > > I'm thinking a text-factory could do this? > > -- > 7-Up? What happened to Ups 1-6? > > -- > You received this message because you are subscribed to the > "BBEdit Talk" discussion group on Google Groups. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/bbedit?hl=en > If you have a feature request or would like to report a problem, > please email "[email protected]" rather than posting to the group. -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/bbedit?hl=en If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.
